我正在裁剪图像,图像裁剪得很好,但在我查看裁剪后的图像时,它会从一些随机位置裁剪图像,我不知道为什么会发生这种情况。我关注此帖http://mrbool.com/jquery-crop-cropping-images-with-jcrop/26243
<form id="crop_form" action="crop.php" method="post">
<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" />
<input type="hidden" name="src" id="src"/>
<input type="hidden" name="original_width" id="original_width" value="<?php echo $row['width']; ?>"/>
<input type="hidden" name="original_height" id="original_height" value="<?php echo $row['height']; ?>"/>
<a id="image_crop" name="image_crop" >
<img src="images/icon-01.png" width="41" height="41" alt="" />
</a>
</form>
</div>
<?php
$width = $row['width'];
$height = $row['height'];
?>
<img title="" id="main_image" src="<?php echo "patternimages/" . $row['img_name'] ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>"> </div>
以下是我的JS代码
$(function() {
var main_image_src = jQuery('#main_image').attr('src');
jQuery('#src').val(main_image_src);
jQuery('#image_crop').on('click', function() {
// checkCoords();
jQuery('#crop_form').submit();
});
$('#main_image').Jcrop({
aspectRatio: 1,
onSelect: updateCoords,
});
});
function updateCoords(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
}
这里是Crop.php
<?php
session_start();
$targ_w = $targ_h = 150;
$jpeg_quality = 90;
$src = $_POST['src'];
$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, 'dummy.jpg', $jpeg_quality);
exit;