2
我正在使用Jcrop图像上传/裁剪功能。第一部分工作正常,但实施Crop导致头痛。我看过thefollowingquestions,没有一个与我的问题完全相关。裁剪与Jcrop和PHP GD创建黑色JPEG
我的表单创建上传:
<img src="uploads/<?=$image_name?>" id="crop-me">
<form action="complete.php" method="post">
<input type="hidden" name="image_name" value="<?=$image_name?>">
<input type="hidden" name="x" id="x">
<input type="hidden" name="y" id="y">
<input type="hidden" name="x2" id="x2">
<input type="hidden" name="y2" id="y2">
<input type="hidden" name="w" id="w">
<input type="hidden" name="h" id="h">
<div class="form-group text-right">
<button type="submit" class="btn btn-primary">Crop</button>
</div>
</form>
我Jcrop的javascript:
$(document).ready(function() {
$('#crop-me').Jcrop({
aspectRatio: 130/170, // 0.7647
minSize: [130, 170],
setSelect: [260, 340, 0, 0],
onChange: showCoords,
onSelect: showCoords
});
function showCoords(c) {
$("#x").val(c.x);
$("#y").val(c.y);
$("#x2").val(c.x2);
$("#y2").val(c.y2);
$("#w").val(c.w);
$("#h").val(c.h);
}
});
最后,complete.php
它执行图像生成:
<?php
$targ_w = 130;
$targ_h = 170;
$jpeg_quality = 100;
$src = 'uploads' . $_POST['image_name'];
$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);
?>
我得到的图像在complete.php
,在130x170尺寸,但它完全是黑色的。我想认为这可能是与纵横比计算/错位(我使用的代码是从Jcrop的tutorial/manual直接撕裂,但宽度和高度不同),但我真的不确定。
有人可以看到我要去哪里吗?
注:我查过,并且服务器绝对是运行GD扩展,V2.X
“上传”后是否需要斜线? '$ src ='uploads /'...' – bloodyKnuckles
为什么是的,是的。谢谢,修正! – mpdc