3

这是我第一次使用 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) ?

提前致谢。

毛罗

4

1 回答 1

3

如果要保存文件而不是输出文件,请执行以下两件事:

  • 删除线header('Content-type: image/jpeg');
  • 将之后的下一行更改为imagejpeg($dst_r, 'path/to/output.jpg', $jpeg_quality);

请参阅php.net/imagejpegimagejpeg()上的函数文档

于 2011-03-05T18:27:05.727 回答