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

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

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?

  • 写回答

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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 爬虫爬取网站的一些信息
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错