PHP图像输出问题

PHP图像输出问题,php,image,header,export,Php,Image,Header,Export,我在使用php生成和导出图像时遇到问题 所以我有这个: header('Content-type: image/jpeg'); header('Content-Disposition: inline; filename=WHATEVER.jpg'); $dragon = self::static_dragon($numbers,$avatars,$new_name,$filepath); 在static_dragon函数中,我从数据库加载数据,处理数据,等等,然后: imagejpeg($ca

我在使用php生成和导出图像时遇到问题

所以我有这个:

header('Content-type: image/jpeg');
header('Content-Disposition: inline; filename=WHATEVER.jpg');
$dragon = self::static_dragon($numbers,$avatars,$new_name,$filepath);
在static_dragon函数中,我从数据库加载数据,处理数据,等等,然后:

imagejpeg($canvas,'',60);
imagedestroy($canvas); 
return true;
我想要实现的是,如果我写

它会给我图像。 一切正常,数据库连接,甚至在服务器上保存最终的jpg文件,唯一的问题是浏览器没有显示图像。我想标题可能有问题吧? 顺便说一句,我不能在函数之后执行头,因为脚本告诉我头已经被发送了(即使我没有看到任何这样做的命令…)


非常感谢您的帮助

难道您没有忘记添加

 echo $dragon
php文件内容中的对象?:) 将此行添加到php文件的末尾:

echo $dragon

难道你没有忘记添加

 echo $dragon
php文件内容中的对象?:) 将此行添加到php文件的末尾:

echo $dragon
你也在做同样的事情吗:

header('Content-type: image/jpeg');
header('Content-Disposition: inline; filename=WHATEVER.jpg');

$im = imagecreatefromjpeg('download.jpg') or  or die('Cannot Initialize new GD image stream'); // this will let u know whether the creation of image resource was a failure

imagestring($im, 3, 40, 20, 'GD Library', 0xFFBA00); //just a add on 

imagejpeg($im);
imagedestroy($canvas);
return true;
上述代码在浏览器中运行良好。有错误吗

@Tom,正如您提到的,您收到错误:imagecreatefromjpeg的“标题已发送”。首先解决错误,因为imagecreatefromjpeg()为图像提供了资源。如果资源出现故障,则图像将不可见

尝试使用@imagecreatefromjpeg()

您是否也这样做:

header('Content-type: image/jpeg');
header('Content-Disposition: inline; filename=WHATEVER.jpg');

$im = imagecreatefromjpeg('download.jpg') or  or die('Cannot Initialize new GD image stream'); // this will let u know whether the creation of image resource was a failure

imagestring($im, 3, 40, 20, 'GD Library', 0xFFBA00); //just a add on 

imagejpeg($im);
imagedestroy($canvas);
return true;
上述代码在浏览器中运行良好。有错误吗

@Tom,正如您提到的,您收到错误:imagecreatefromjpeg的“标题已发送”。首先解决错误,因为imagecreatefromjpeg()为图像提供了资源。如果资源出现故障,则图像将不可见


尝试使用@imagecreatefromjpeg()

来代替$canvas,使用以下命令:

$this->getResponse()->setContent($canvas)

在php文件的头部

(我假设$canvas是从DB加载的对象)


请确保您没有在php文件中打印任何其他内容

因此,与其使用$canvas,不如使用以下内容:

$this->getResponse()->setContent($canvas)

在php文件的头部

(我假设$canvas是从DB加载的对象)


请确保您没有在php文件中打印任何其他内容

在设置标题之前,是否回显任何内容?即使在
No,nothing之前只有空格,“header ready sent”错误,我告诉我header是在线发送的:$handler=imagecreatefromjpeg($picture);这对我来说毫无意义。你是否检查过没有生成错误或警告消息?在设置标题之前,你是否回显了任何内容?即使在
No,nothing之前只有空格,“header ready sent”错误,我告诉我header是在线发送的:$handler=imagecreatefromjpeg($picture);这对我来说毫无意义。你检查过没有生成错误或警告消息吗?我也这么认为,但也没什么帮助。我也这么认为,但也没什么帮助。啊,现在我在想,是的,它确实给了我图像资源错误,这可能是“已发送错误”。imagecreatefromjpeg()和@imagecreatefromjpeg()有什么区别?我将在没有错误的情况下尝试,imagestring()函数是什么?非常感谢。好了,现在我可以把标题放在我想要的地方,但图像仍然没有显示。在Chrome浏览器中,它刚刚损坏的图像,在Firefox中,我看到一条消息:图像“”无法显示,因为它包含错误。还有什么建议吗?谢谢在函数前面有@operaton将阻止向用户的浏览器打印错误消息。我用handler更新了代码。啊,现在我在想,是的,它确实给了我图像资源错误,这可能是“已发送错误”。imagecreatefromjpeg()和@imagecreatefromjpeg()有什么区别?我将在没有错误的情况下尝试,imagestring()函数是什么?非常感谢。好了,现在我可以把标题放在我想要的地方,但图像仍然没有显示。在Chrome浏览器中,它刚刚损坏的图像,在Firefox中,我看到一条消息:图像“”无法显示,因为它包含错误。还有什么建议吗?谢谢在函数前面使用@operaton将阻止向用户的浏览器打印错误消息。我已使用handler更新了代码。