【发布时间】:2015-08-03 15:56:33
【问题描述】:
我正在尝试从命令行使用 imagemagick(在 php 中,是的,我知道我可以使用 imagemagick 函数,但这不是一个选项)而不保存到最终文件,只是将最终图像读取到标准输出。这是我的代码:
$filename = <filepathandname>;
$cmd = IMCMD. $filename . " -resize 105% -";
header('Content-Disposition: inline; filename="'.$filename.'"');
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($filename));
header('Content-Type: image/jpeg');
//from here to end returns an empty image
ob_start();
passthru($cmd, $result);
$out = ob_get_contents();
ob_end_clean();
echo ($out);
//end
//readfile($filename); //otherwise this works fine
exit();
我得到的是一个空图像(0 字节)。我已经从这个网站上的问题中尝试了很多其他组合,比如简单地回显 STDOUT 等等,但我认为真正的问题是我不太了解 convert.exe 如何发送到标准输出以及一般处理标准输出。
有任何 php / convert.exe 专家在这里看到任何明显的东西吗?
【问题讨论】:
-
另外,如果我将输出文件名分配给 convert.exe 命令字符串(而不是 - ),则该操作将应用于文件,因此我知道该命令的语法是正确的。
标签: php stdout imagemagick-convert