So this is the original picture including the rectangle, I want to create a cropped Image from
And this is what I get after the cropping
So it can be seen, that the new image has the right dimensions but the wrong part is being cropped. Here's the JS:
$(document).ready(function()
{
$('#cropimage').Jcrop(
{
aspectRatio: 3 / 4,
maxSize: [150,200],
onSelect: updateCoords
});
});
function updateCoords(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
And here is the PHP code
function crop($_POST)
{
$clipX = (int)$_POST['x'];
$clipY = (int)$_POST['y'];
$filename = (string)$_POST['image'];
$resizedHeight = (int)$_POST['h'];
$resizedWidth = (int)$_POST['w'];
// Original image's details
$original = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'images/user_pictures/' . DIRECTORY_SEPARATOR . $filename;
$dimensions = getimagesize($original);
$old_width = $dimensions[0];
$old_height = $dimensions[1];
// image = original_image
$old_image = call_user_func('imagecreatefrom' . 'jpeg', $original);
// Crop image
if (function_exists('imagecreatetruecolor') && ($new_image = imagecreatetruecolor($resizedWidth, $resizedHeight)))
imagecopyresampled($new_image, $old_image, 0, 0, $clipX, $clipY, $resizedWidth, $resizedHeight, $old_width, $old_height);
imagejpeg($new_image,'images/user_pictures/'.$this->getUserID().'_picture.jpg');
}
I never used those php functions before but I've read some tutorials and I dont see any errors there. But there must be at least 1 ... what am I doing wrong ? The while original Image seems to be resized for whatever reason.