0
我試圖用jcrop
,以允許用戶創建自己的圖像的縮略圖,這將是190x190 pixels
。PHP - imagecopyresampled
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是否鎖定到1.0寬高比,如您的目的地190x190圖像? – jimp 2013-03-14 02:30:23
Jcrop鎖定到1:1的正方形選擇區域,但據我imagecopyresampled的理解,不應該有所作爲呢。正確? – Fittersman 2013-03-14 03:17:35
是的,你是對的。我認爲不正確的寬高比可能會導致縮放效果,但它確實會導致一個維度上的拉伸或縮小。是否有現場示例或由此產生的圖像?我開始認爲問題可能在其他地方。你的代碼看起來不錯。 – jimp 2013-03-14 03:51:50