【问题标题】:Jpeg image Creating Problems with PHP GD libraryJpeg 图像使用 PHP GD 库创建问题
【发布时间】:2014-09-08 20:34:19
【问题描述】:

如果我尝试从现有的 .jpeg 图像创建新图像,则会给出黑色(空白)图像。

我的代码:

$new_path = 'post/'.time().'-myimage.jpeg';
$src="post/myimage.jpeg";
$jpeg_quality = 90;
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor($my_post['w'], $my_post['h']);    
   imagecopyresampled($dst_r,$img_r,0,0,$my_post['x'],$my_post['y'],$my_post['w'],$my_post['h'],$my_post['w'],$my_post['h']);
    header('Content-Type: image/jpeg');
    imagejpeg($dst_r, $new_path, $jpeg_quality);

【问题讨论】:

    标签: php gdlib


    【解决方案1】:

    如果您在imagejpeg 中使用文件名,则 jpeg 不会输出到标准输出 - 它会保存到给定的文件名。您必须使用null 作为文件名。

    imagejpeg($dst_r, null, $jpeg_quality);
    

    如果您还想保存图片,则必须调用该函数两次或使用readfile 之类的函数将文件内容重定向到服务器。

    【讨论】:

    • 当我尝试保存 jpg 时,它可以工作,但不适用于 jpeg,我也想将 .jpeg 保存到新路径但不工作。
    • jpg 和 jpeg 是一样的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-10
    • 1970-01-01
    • 2011-06-02
    • 2012-10-14
    • 2020-04-24
    • 2011-09-01
    • 1970-01-01
    相关资源
    最近更新 更多