2
I already reversed the parameters several times to check if I was passing them erroneously, but I was not successful. What is happening is that Crop is performed in a different location than specified. I am using jQuery and jCrop plugin to find the coordinates. On the client side everything works normal.
As in the image below:
I selected the area that is in the print above and it cropped in a totally different location:
Initialization of Jcrop
$('#target').Jcrop({
onSelect: showCoords,
onChange: showCoords,
aspectRatio: 960/720,
boxWidth: 600,
boxHeight: 400,
bgColor: '#674323'
});
This is PHP script where I do 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;
}
Checks if the cutting position values are correct, it is assuming the cutting position as 0 x 0.
– touchmx
@touchmx I am using '0.0' because this is the destination X, Y respectively of the target image. In kids this is coordinated where the copied image will be pasted with the function. In my view this parameter is for this. Correct me if you disagree.
– Luitame
@bfavaretto can you do this by exemplifying with the function? Please. I don’t understand exactly what you wanted to give me.
– Luitame
@Has Luitame checked in the php documentation if the parameters passed are correct? http://php.net/manual/en/function.imageresampled.php
– touchmx
@touchmx checked yes, but I can’t understand clearly. This is the part where I’m in doubt.
– Luitame