JCrop裁剪错误的区域

时间:2016-05-28 14:48:59

标签: php jcrop

我需要一些帮助来实现JCrop。我试图按照手册,但每当我选择一个区域时,它实际上并没有选择我选择的内容。相反,它在我的选择之外占据了一些区域。有时,它几乎正确地占领了这个区域(我正在考虑因为照片尺寸),但大多数情况下这是错误的区域。请帮忙。这是我的代码:

注意$ photo是上传的图片。它被正确上传,所以没有问题。

120 x 120是我想保存上传图片的像素,以节省存储空间。另外,这是<img>元素的css,我在其中显示裁剪图像:

max-width: 100%;
height: auto;
display: inline-block;
position: relative;    

这是我的PHP代码:

$twidth = 120;
$theight = 120;
$quality = 90;
$src = imagecreatefromjpeg($photo);
$dst = ImageCreateTrueColor($twidth, $theight);
$x = $_POST['x'];
$y = $_POST['y'];
$w = $_POST['w'];
$h = $_POST['h'];
imagecopyresampled($dst, $src, 0, 0, $x, $y, $twidth, $theight, $w, $h);
imagejpeg($dst, $photo, $quality);

1 个答案:

答案 0 :(得分:1)

这里的问题是你用css调整图像框的大小。这为脚本找到正确的区域造成了困难。 相反,您应该使用Jcrop函数限制框宽度/高度,如下所示:

$('#cropbox').Jcrop({
        boxWidth: 480,   //Maximum width you want for your bigger images
        boxHeight: 480,  //Maximum Height for your bigger images
...
});

如果您使用此Jcrop设置,它将占用所需区域,否则它将无法按预期工作。

祝福