drj26159
2013-03-06 20:53
浏览 45
已采纳

裁剪图像中的错误在哪里?

Good day.

i have problem with a crop image.

original image:

original

after use code i give next image:

last

Code for crop image:

$pathTemp = '../Images/Temp/';
$path = '../Images/';
$pathCrop = '../Images/Crop/';


if($image=='0'){die('error_image');}
if (!copy($pathTemp.$image, $path.$image)){die('error_image');}

$ext_arr = explode('.',$image);
$ext = $ext_arr[1];

$jpeg_quality = 90;
$src = $pathCrop.$image;

$img_r = imagecreatefromjpeg($src);

$dst_r = imagecreatetruecolor($_POST['w'], $_POST['h']);

imagecopyresized($dst_r,$img_r,0,0,$_POST['x1'],$_POST['y1'],170,110,$_POST['w'],$_POST['h']);

imagejpeg($dst_r,$pathCrop.time().'.jpg',$jpeg_quality);

Tell me please where i have error?

Why i get bad end image?

图片转代码服务由CSDN问答提供 功能建议

美好的一天。

我的裁剪图像有问题。

原始图片:

使用代码后我给出下一张图片:

代码 作物图像:

  $ pathTemp ='../Images/Temp/';
$path ='../ images /'; 
  $ pathCrop ='../Images/Crop/';
nnnif($image,'0'){die('error_image');}
if(!copy($ pathTemp。$ image,$ 路径。$ image)){die('error_image');} 
 
 $ ext_arr = explode('。',$ image); 
 $ ext = $ ext_arr [1]; 
 
 $ jpeg_quality =  90; 
 $ src = $ pathCrop。$ image; 
 
 $ img_r = imagecreatefromjpeg($ src); 
 
 $ dst_r = imagecreatetruecolor($ _ POST ['w'],$ _POST ['h']  ); 
 
imagecopyresized($ dst_r,$ IMG_R,0,0,$ _ POST [ 'X1'],$ _ POST [ 'Y1'],170110,$ _ POST [ 'W'],$ _ POST [ 'H']  ); 
 
imagejpeg($ dst_r,$ pathCrop.time() 'JPG。',$ jpeg_quality); 
   
 
 

请告诉我哪里有错误?

为什么我 得到糟糕的结局图像?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsam70528 2013-03-06 21:46
    已采纳

    Your script works, I think that your problem is the location of the original image.

    Isn't your original image supposed to be in the $path folder ? You're looking for it in the $pathCrop folder.

    $src = $pathCrop.$image;
    

    Then $img_r is empty, so when you copy it to $dst_r you have a black image.

    Try replacing

    $src = $pathCrop.$image;
    

    by

    $src = $path.$image;
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题