【问题标题】:PHP Imagemagick - passthru not working when trying to output a image without saving to the local folderPHP Imagemagick - 在尝试输出图像而不保存到本地文件夹时,passthru 不起作用
【发布时间】:2013-03-18 12:55:08
【问题描述】:

在下面的代码中,我试图通过 imagemagick 处理输出图像。在这里,我将边框半径应用于输入图像。当我使用以下代码将图像保存到输出文件夹时,我得到了输出。

<?php
$input = "input.png";
$s = 10;
$t = 10;
$size = getimagesize ( $input );
$output = $outputfolder . $outputname;
exec( "convert -size " . $size [0] . "x" . $size [1] . " xc:none -fill -transparent 
-draw \"roundRectangle 0,0 " . $size [0] . "," . $size [1] . " $s,$t\"  " . $input .
" -compose SrcIn -composite " . $output . " " );
?>

我想要一个尚未保存到本地文件夹但想要显示带有标题内容类型的输出的输出。我正在使用 passthru 来执行此操作。但我没有得到输出。我正在尝试使用以下代码

    <?php
$input = "input.png";
header("Content-Type: image/png");
$size = getimagesize ( $input );
$s = 10;
$t = 10;
$cmd =  " - size " . $size [0] .
              "x" . $size [1] . " xc:none -fill -transparent  -draw
\"roundRectangle 0,0 " .
                $size [0] . "," . $size [1] . " $s,$t\"  " .
                 " -compose SrcIn -composite" .
                " -tile - $input";

passthru("convert $cmd PNG :-")

?>

我认为我使用的命令有误。请帮助我。提前致谢。

【问题讨论】:

  • 回显命令,并通过控制台手动运行它,查看命令是否输出您所期望的。如果该命令不产生任何数据,它不会将任何内容传递给 passthru

标签: php imagemagick passthru


【解决方案1】:

您能解释一下您现在想要保存文件的原因吗?转换图像的目的是什么?

在我得到这些额外信息之前,我会四处走动,并假设图像正在作为 CMS 的一部分上传并经过调整以适应布局,然后显示给用户?

如果我个人是这种情况,我会保存输出文件,然后执行类似显示它的操作。

header("Content-Type: image/png");
echo file_get_contents($pathToImage)

您可以在运行 image magick 之前检查文件是否已经存在。这可能比每次显示时都重新处理图像更有效

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    • 2016-03-09
    相关资源
    最近更新 更多