【发布时间】:2013-03-02 06:10:17
【问题描述】:
我正在尝试使用jcrop 来允许用户创建他们图像的缩略图,它将是190x190 pixels。
jcrop 似乎正在工作并向我发送正确的坐标。然而,imagecopyresampled 似乎表现得非常不可预测,并没有给我我所期望的。这是我的代码:
$destWidth = $destHeight = 190;
$jpeg_quality = 90;
$path = Yii::app()->basePath."/../images/user/";
$src = $path.$model->image;
$img_src = imagecreatefromjpeg($src);
$img_dest = ImageCreateTrueColor( $destWidth, $destHeight );
imagecopyresampled(
$img_dest, //destination image
$img_src, //source image
0, //top left coordinate of the destination image in x direction
0, //top left coordinate of the destination image in y direction
$_POST['x'], //top left coordinate in x direction of source image that I want copying to start at
$_POST['y'], //top left coordinate in y direction of source image that I want copying to start at
$destWidth, //190, thumbnail width
$destHeight, //190, thumbnail height
$_POST['w'], //how wide the rectangle from the source image we want thumbnailed is
$_POST['h'] //how high the rectangle from the source image we want thumbnailed is
);
imagejpeg($img_dest,$path."thumbs/test.jpg",$jpeg_quality);
我很茫然,我检查了四个$_POST 变量是否都正确输入,但由于某种原因我无法获得正确的缩略图。我可以肯定的是,缩略图通常被放大太多,而且我希望它开始的左上角没有被使用。
【问题讨论】:
-
Jcrop 是否像您的目标 190x190 图像一样锁定为 1.0 纵横比?
-
Jcrop 被锁定在一个 1:1 的正方形选择区域,但就我对 imagecopyresampled 的理解而言,无论如何都不应该有所作为。对吗?
-
是的,你是对的。我在想不正确的纵横比可能会导致缩放效果,但实际上只会导致一维的拉伸或收缩。是否有现场示例或生成的图像可供查看?我开始认为问题可能出在其他地方。您的代码看起来不错。
-
发现我的问题,看下面的帖子
-
问题中的客户端变量。说得通。感谢您发布您的解决方案。