【问题标题】:Cropping image in PHP imagecopyresampled - squashing instead of cropping在 PHP imagecopyresampled 中裁剪图像 - 挤压而不是裁剪
【发布时间】:2012-09-19 04:32:48
【问题描述】:

我正在使用 jCrop 来裁剪图像。这段代码之前在另一个页面上运行,但是当我为另一个页面实现它时,它似乎正在播放。

当我运行它时,代码会拍下原始图像,将其压扁,然后将整个图像放入我打算裁剪到的框中。

$_POST 值中的值从 jCrop 正确返回。

$origURL=$_POST['CelebrityPicURL'];
$x = $_POST['x'];
$y = $_POST['y'];
$w = $_POST['w'];
$h = $_POST['h'];

$targ_w = $targ_h = 300;
$jpeg_quality = 90;

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

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


imagejpeg($dst_r,$origURL,$jpeg_quality);

【问题讨论】:

    标签: php jquery image jcrop


    【解决方案1】:

    您可以简单地使用imagecopy()。比如……

    $dst_r = imagecreatetruecolor((int) $w, (int) $h);
    imagecopy($dst_r, $img_r, 0, 0, (int) $x, (int) $y, (int) $w, (int) $h);
    

    当然,您还需要检查越界情况并适当地处理它们。如果您从 $_POST 数组中获取裁剪数据,不确定为什么要设置和/或使用 $targ_w 和 $targ_h。

    【讨论】:

      猜你喜欢
      • 2011-06-25
      • 2011-03-18
      • 2016-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-20
      • 2022-01-23
      • 2011-07-14
      相关资源
      最近更新 更多