发送内容类型图像/TIFF到浏览器不工作


send content type image/TIFF to the browser is not working

我使用的是Imagick(6.7.7-4和模块版本3.2.0RC)

我正在尝试创建一个图像并动态地在浏览器中呈现它,例如,通过HTML

<img src='image_generator.php?QUERY_PARAMS_TO_DETERMINE_TEXT'>

image_generator.php的内容:

/* Create text */
$draw->setFillColor('white');
$draw->setFontSize( 19 );
$draw->setGravity(Imagick::GRAVITY_CENTER);
$draw->annotation(0, -50, 'points');
$image->drawImage($draw);
/* Give image a format */
$image->setImageFormat('tiff'); // png works
/* Output the image with headers */
header('Content-type: image/tiff'); // png works
echo $image;

当我在php中打开image_generator.php并将图像格式设置为TIFF时,它会自动下载一个php文件,并且不显示PNG情况下的图像。

如果将下载文件的扩展名更改为"结果是正确的图像,那么,问题是,浏览器正在使用页面名称作为文件名。当服务器端脚本或applet以编程方式提供图像(或其他供下载的文件)时,这并不罕见。

更改附件"

/* Give image a format */
$image->setImageFormat('tiff'); // png works
/* Output the image with headers */
// This line will change the download name
header('Content-Disposition: attachment; filename="[NAME.TIFF]");
// This line will set the Mime Type
header('Content-type: image/tiff'); 
echo $image;

我知道我迟到了很多年,但是,因为很多人遇到这个问题,认为这是糟糕的代码或配置,或者只是需要知道如何重命名他们的下载,我想我应该为其他人回答这个问题。