这是我处理gd的第一个方法。
我正在尝试使用jcrop jquery插件实现resize和crop。
我仍然不知道如何保存我裁剪的图像。在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;
}

我该如何处理image jpeg($dst_r,null,$jpeg_quality),以便实际写入图像文件并将其路径保存在我的数据库中?
提前谢谢。
毛罗

最佳答案

如果要保存文件而不是输出文件,请执行以下两项操作:
删除行header('Content-type: image/jpeg');
将其后的下一行更改为imagejpeg($dst_r, 'path/to/output.jpg', $jpeg_quality);
参见php.net/imagejpegimagejpeg()函数的文档

关于php - php jquery jcrop和imagejpeg,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5205821/

10-10 23:54