I have already inverted the parameters several times to check if I was passing them wrong, but I did not succeed. What is happening is that the crop is carried out in a different location than specified. I'm using jQuery and the jCrop plugin to find the coordinates. On the client side everything works fine.
As in the image below:
Iselectedtheareathatisintheprintaboveanditcroppedinatotallydifferentlocation:
Jcrop startup
$('#target').Jcrop({
onSelect: showCoords,
onChange: showCoords,
aspectRatio: 960/720,
boxWidth: 600,
boxHeight: 400,
bgColor: '#674323'
});
This is PHP script where I crop on Server-side:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$dst_x = 0;
$dst_y = 0;
$src_x = ceil($_POST['x']); // x1 da imagem de origem
$src_y = ceil($_POST['y']); // y1 da imagem de origem
$dst_w = ceil($_POST['w']); // largura da imagem de destino
$dst_h = ceil($_POST['h']); // altura da imagem de destino
$src_w = ceil($_POST['x2']); // x2 da imagem de origem
$src_h = ceil($_POST['y2']); // y2 da imagem de origem
$jpeg_quality = 100;
$src = 'css/images/luitame.jpg';
$img_r = imagecreatefromjpeg($src);
$dst_r = imagecreatetruecolor($_POST['w'], $_POST['h']);
$imageName = "css/images/thumbs/".time().'.jpg';
imagecopyresampled($dst_r, $img_r, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
imagejpeg($dst_r, $imageName, $jpeg_quality);
header("location: result.php?img=$imageName");
exit;
}