I'm trying to implement jcrop function but the output of my cropped image is wrong. Here below are my parts of code. The first part is the PHP script that is called from the POST form at the bottom of my code. After the PHP script there is the JQuery script. And at the bottom there is the form I use to submit the coords of the image I want to crop.
'''
***PHP script**
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$targ_w = 800;
$targ_h = 800;
$jpeg_quality = 100;
$src='images/boolprv.jpg';
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
header('Content-type: image/jpeg');
imagejpeg($dst_r,null,$jpeg_quality);
imagedestroy($dst_r);
exit;
}
?>
***** jquery script ***
<script language="Javascript">
$(function(){
$('#cropbox').Jcrop({
aspectRatio: 1,
onSelect: updateCoords
});
});
function updateCoords(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
function checkCoords()
{
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
</script>
*****HTML form****
<img src= "images/boolprv.jpg" width="800" id="cropbox" />
<form action="cropfirst.php" method="post" onsubmit="return checkCoords();">
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
Nome: <input type="text" name="nome"><br>
Cognome: <input type="text" name="cognome"><br>
<input type="submit" value="Crop Image" />
</form>
'''
Result is a wrong cropped area as in 1 you can see the area I want to crop, but in 2 there's the result I get from the Imagejpeg() function.
Could anyone please help me? Thanks