php jquery jcrop 和 imagejpeg
这是我第一次接触 GD 的东西。 我正在尝试使用 jcrop jquery 插件实现调整大小和裁剪。 我仍然不知道如何保存裁剪后的图像。 jcrop 网站上没有太多相关内容。这是我的代码:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$targ_w = $targ_h = 150;
$jpeg_quality = 90;
$src = 'demo_files/flowers.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);
exit;
}
如何使用 imagejpeg($dst_r,null,$jpeg_quality) 来实际写入图像文件并将其路径保存在我的数据库中?
提前致谢。
毛罗
That's my first approach with GD stuff.
I'm trying to implement resize and crop using jcrop jquery plugin.
I still can't figure out how to save the image I've cropped. On the jcrop site there's not much about it. here's my code:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$targ_w = $targ_h = 150;
$jpeg_quality = 90;
$src = 'demo_files/flowers.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);
exit;
}
What do I do with imagejpeg($dst_r,null,$jpeg_quality) in order to actually write the image file and save its path in my db?
Thanks in advance.
Mauro
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想保存文件而不是输出它,请执行以下两件事:
header('Content-type: image/jpeg');
imagejpeg($dst_r, 'path/to/output.jpg', $jpeg_quality);
请参阅 php.net/imagejpeg
If you want to save the file instead of outputting it, do these two things:
header('Content-type: image/jpeg');
imagejpeg($dst_r, 'path/to/output.jpg', $jpeg_quality);
See the docs for the
imagejpeg()
function at php.net/imagejpeg