我正在尝试使用jcrop保存基于x,y,w,h的裁剪图像。我将x,y轴和宽度/高度发送到我的PHP文件,但裁剪区域错误。
这是我的PHP功能
$axis_x = $_POST["x"];
$axis_y = $_POST["y"];
$width = $_POST["w"];
$height = $_POST["h"];
$path_foto = "imgs/3.jpg";
$targ_w = $width;
$targ_h = $height;
$jpeg_quality = 90;
$src = $path_foto;
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r, $img_r, 0, 0, $axis_x, $axis_y, $width, $targ_w, $targ_h, $height);
imagejpeg($dst_r, $path_foto, $jpeg_quality);
每次变红图像时,jcrop都会在隐藏的输入中设置此坐标。问题总是出在错误的区域。
我做错了什么?
(在不知道结果有什么“错误”的情况下,很难为您提供帮助。)
但是您正在/可能遇到的一些明显问题:
您呼叫的参数顺序imagecopyresampled()
有误:最后4个参数应为$targ_w, $targ_h, $width, $height
Ref
“坐标是指左上角。” 参考
这意味着它y = 0
位于图像的顶部,而不是底部。因此,如果您$_POST["y"]
是图像底部的像素数,则需要从原始图像的高度中减去该值,然后它才能按预期工作。
获取您的代码,并使用一些硬编码的值:
<?php
$axis_x = 115;
$axis_y = 128;
$width = 95;
$height = 128;
$path_foto = "/Users/gb/Downloads/original.jpg";
$targ_w = $width;
$targ_h = $height;
$jpeg_quality = 90;
$src = $path_foto;
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r, $img_r, 0, 0, $axis_x, $axis_y, $targ_w, $targ_h, $width, $height);
imagejpeg($dst_r, "/Users/gb/Downloads/cropped.jpg", $jpeg_quality);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句