PHP未捕获异常'ImagickException',消息'FailedToExecuteCommand'

时间:2014-06-19 04:30:56

标签: php pdf imagemagick ghostscript

我已经通过pecl在MAC上安装了ImageMagick PHP扩展。它显示在phpinfo()下,并将PDF列为支持的格式。

我试图读取PDF并将其转换为图像。但是,当源是PDF时,构造函数会引发异常。图像文件成功运行。

$im = new imagick('TestDoc.pdf[0]'); // Throws Exception when PDF specified.
//$im = new imagick('TestImage.png'); // Succeeds.
$im->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $im;


Fatal error: Uncaught exception 'ImagickException' with message 'FailedToExecuteCommand 
`"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -
dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 
"-r72x72" -dFirstPage=1 -dLastPage=1 "-sOutputFile=/var/tmp/magick-43594XlaRxeGWg1ps%d" "-
f/var/tmp/magick-43594O_WVqnAJTgzr" "-f/var/tmp/magick-43594ivJ_pKBcF3s7"' (-1) @ 
error/utility.c/SystemCommand/2029' in 
/Users/garys/Documents/Projects/accrivia/code/test/test.php:8 Stack trace: #0 
/Users/garys/Documents/Projects/accrivia/code/test/test.php(8): Imagick-
>__construct('../TestDoc.pdf[...') #1 {main} thrown in 
/Users/garys/Documents/Projects/accrivia/code/test/test.php on line 8

创建输出中提到的tmp文件,但是为0字节。如果我执行完整的'在命令行中使用命令(使用实际文件),它可以成功运行。

使用brew安装了ImageMagick和GhostScript。

在PHP中,系统(' echo $ PATH');给/ usr / bin:/ bin:/ usr / sbin:/ sbin ' GS'在/ usr / bin /

有没有人有任何建议。对异常消息的Web搜索没有任何特定信息。

非常感谢 加里。

2 个答案:

答案 0 :(得分:2)

我自己从未使用过imageMagick,但文档说它需要GhostScript来阅读PDF文档

PDF support :   Requires Ghostscript to read. 

编辑:您是否检查过GhostScript正在运行?

答案 1 :(得分:0)

我在Homebrew安装的MacOS High Sierra,PHP 7.0上遇到了同样的问题。问题是FPM $PATH包含(由<php echo getenv('PATH'); ?>/usr/bin:/bin:/usr/sbin:/sbin回复,其中不包含Brew的/usr/local/bin/安装路径。

要解决我添加

env[PATH] = /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

/usr/local/etc/php/7.0/php-fpm.d/www.conf,重启php70并开始工作!在Homebrew's forums @comes建议将其添加到.env文件

相关问题