这是我对 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) 才能实际写入图像文件并将其路径保存在我的数据库中?
提前致谢。
毛罗
最佳答案
如果你想保存文件而不是输出它,做这两件事:
- 删除行
header('Content-type: image/jpeg');
- 将其后的下一行更改为
imagejpeg($dst_r, 'path/to/output.jpg', $jpeg_quality);
请参阅 php.net/imagejpeg 上关于 imagejpeg()
函数的文档
关于php jquery jcrop 和 imagejpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5205821/