我正在尝试使用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
变量是否都正确输入,但由于某种原因我无法获得正确的缩略图。我可以肯定的是,缩略图通常放大太多,并且我希望它开始的左上角没有被使用。