I've been working on this for ages and can't find a problem anywhere. I'm trying to use jcrop to allow users to create a thumbnail of their image, it will be 190x190 pixels.
jcrop seems to be working and sending me the correct coordinates. However, imagecopyresampled seems to be acting very unpredictably and not giving me what I expect. Here is my code:
$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);
I'm seriously at a loss, I've checked that the four $_POST variables are all coming in correctly, but for some reason I can't get a proper thumbnail. All I can tell for sure is that the thumbnail is usually zoomed in too much and that the top left corner I want it to start from isn't being used.