Friday, 31 August 2018

PHP + JCrop - Cropping wrong area

I'm trying to save an cropped image with jcrop, based on x,y,w,h. I send to my PHP file, the axis x,y and width/height, but the cropped area is wrong.

this is my php function

$axis_x = $_POST["x"];
$axis_y = $_POST["y"];
$width = $_POST["w"];
$height = $_POST["h"];
$path_foto = "imgs/3.jpg";
$targ_w = $width;
$targ_h =  $height;
$jpeg_quality = 90;
$src = $path_foto;
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);

imagecopyresampled($dst_r, $img_r, 0, 0, $axis_x, $axis_y, $width, $targ_w, $targ_h, $height);

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

This coords is set by jcrop in an input hidden everytime when the image is redized. The problem is always crop the wrong area.

What i'm doing wrong?



from PHP + JCrop - Cropping wrong area

No comments:

Post a Comment