0

实际情况

2008 年初的 MacBook Pro

OSX 狮子 10.7.3

MAMP 2.0.5

ImageMagick-x86_64-apple-darwin11.3.0.tar.gz - 从终端安装并完美运行

gplgs-8.71.dmg - 从终端和 Imagick 安装并完美运行

什么有效?

使用终端“转换”命令可以完美运行!我可以毫无问题地将PDF转换为JPG...

问题是什么?

如果我尝试在 PHP 中使用 Imagick 午餐(最简单的)演示命令:

“转换标志:logo.gif”

什么都没发生!我一步一步地遵循了这个指南,我知道我必须修改“envvars”文件并且我做到了,但是......这不是解决方案!

我试图读取 shell 错误,但 PHP 没有返回任何内容……我尝试了各种命令:

define('MAGICK_PATH', '/Applications/MAMP/bin/ImageMagick/ImageMagick-6.7.5/bin/');

echo exec(MAGICK_PATH.'convert logo: logo.gif', $output);
var_dump($output);
=> array(0) { }


$output = shell_exec(MAGICK_PATH."convert logo: logo.gif");
echo "<pre>$output</pre>";
=> *nothing*


$last_line = system(MAGICK_PATH.'convert logo: logo.gif', $retval);
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
=> Last line of the output:
=> Return value: 5


$last_line = system(MAGICK_PATH.'convert -version', $retval);
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
=> Last line of the output:
=> Return value: 5


$last_line = system(MAGICK_PATH."convert -colorspace RGB -interlace none -density 104.6x104.6 -quality 100 -bordercolor white doc.pdf[0] doc.png", $retval);
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
=> Last line of the output:
=> Return value: 5

我想也许程序没有吃午饭但是......我可以在任务管理器中看到它并且 CPU 工作了几秒钟,Imagick 正在做一些事情,但最后我没有任何输出!!!>_< 我发现了很多关于这个的话题,但我还没有找到一个可行的解决方案......

4

2 回答 2

2

尝试像这样包装命令:

exec($cmd." 2>&1", $out, $ret);
if ($ret){
    echo "There was a problem!\n";
    print_r($out);
}else{
    echo "Everything went better than expected!\n";
}

exec()让您捕获所有输出并获取退出代码。添加2>&1确保重定向STDERR到,STDOUT以便您可以看到任何错误消息。

于 2012-04-09T16:21:53.537 回答
0

Also, as an addendum to my earlier comment: try supplying fully-qualified paths to your input and output filenames. Commands are launched in PHP with a default current working directory - and this may not be the same dir that the script is actually contained within.

If you want to see what your default directory is for system commands, try:

exec('pwd');

If any of your paths have spaces in (or if at any stage they contain user input) you should run your parameters through escapeshellarg() to make sure they will work (and that they are safe to run).

于 2012-04-09T17:39:49.490 回答