gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:44:35 24 4
gpt4 key购买 nike

我已经通过 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/

有没有人有什么建议。在 Web 上搜索异常消息没有找到任何具体信息。

非常感谢加里。

最佳答案

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

PDF support :   Requires Ghostscript to read. 

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

关于PHP 未捕获异常 'ImagickException',消息为 'FailedToExecuteCommand',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24298815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com