【问题标题】:PHP Uncaught exception 'ImagickException' with message 'FailedToExecuteCommand'带有消息“FailedToExecuteCommand”的 PHP 未捕获异常“ImagickException”
【发布时间】:2014-08-09 12:46:04
【问题描述】:

我已经通过 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 字节。如果我在命令行上执行消息中的完整“gs”命令(使用实际文件),它会成功运行。

ImageMagick 和 GhostScript 是通过 brew 安装的。

在 PHP 中,system('echo $PATH');给出 /usr/bin:/bin:/usr/sbin:/sbin 'gs' 在 /usr/bin/

谁有建议。对异常消息的网络搜索没有任何具体结果。

非常感谢 加里。

【问题讨论】:

  • 你知道什么是错的吗?我也有同样的问题

标签: php pdf imagemagick ghostscript


【解决方案1】:

我在从 Homebrew 安装的 PHP 7.0 的 MacOS High Sierra 上遇到了同样的问题。问题是 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 文件中

【讨论】:

    【解决方案2】:

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

    PDF support :   Requires Ghostscript to read. 
    

    编辑:您是否检查过 GhostScript 是否正常工作?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-19
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      • 1970-01-01
      • 2014-08-08
      相关资源
      最近更新 更多