Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 裁剪后图像无法正确显示_Php_Image_Jcrop - Fatal编程技术网

Php 裁剪后图像无法正确显示

Php 裁剪后图像无法正确显示,php,image,jcrop,Php,Image,Jcrop,我正在尝试使用jcrop裁剪图像。裁剪过程正常,但裁剪后图像的高度和宽度不正常。图像始终显示为空白阴影 我的代码是 if ($_SERVER['REQUEST_METHOD'] == 'POST') { $targ_w = $_POST['w'];$targ_h = $_POST['h']; $jpeg_quality = 90; $src = 'amazonaws/'.$_POST['rq']; $type = strtolower(substr(strrchr($src,"

我正在尝试使用jcrop裁剪图像。裁剪过程正常,但裁剪后图像的高度和宽度不正常。图像始终显示为空白阴影

我的代码是

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
 $targ_w =  $_POST['w'];$targ_h = $_POST['h'];
 $jpeg_quality = 90;
 $src = 'amazonaws/'.$_POST['rq'];

  $type = strtolower(substr(strrchr($src,"."),1));
  if($type == 'jpeg') $type = 'jpg';
  switch($type){
    case 'bmp': $img_r = imagecreatefromwbmp($src); break;
    case 'gif': $img_r = imagecreatefromgif($src); break;
    case 'jpg': $img_r = imagecreatefromjpeg($src); break;
    case 'png': $img_r = imagecreatefrompng($src); break;
    default : return "Unsupported picture type!";
  } 

    $img_r = imagecreatefromjpeg($src);
    $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );


  if($type == "gif" or $type == "png"){
    imagecolortransparent($dst_r, imagecolorallocatealpha($dst_r, 0, 0, 0, 127));
    imagealphablending($dst_r, false);
    imagesavealpha($dst_r, true);
  } 
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);


 switch($type){
    case 'bmp': imagewbmp($dst_r,$src); break;
    case 'gif': imagegif($dst_r,$src); break;
    case 'jpg': imagejpeg($dst_r,$src,$jpeg_quality); break;
    case 'png': imagepng($dst_r,$src); break;
  }
}
以下是imagecopyresampled()原型:

bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
在脚本中,指定

$targ_w =  $_POST['w']; $targ_h = $_POST['h'];
当你打电话的时候

imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);
您告诉复制函数源映像与目标映像的大小相同

您需要使用获取原始图像尺寸

list($src_width, $src_height, $src_type, $src_attr) = getimagesize($src) ;
并在复制函数中使用这些维度

imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$src_width,$src_height);