Imagick 不会打开 pdf 文件"Failed to read the file"例外



试图从php脚本中打开PDF文件,并以错误:

Uncaught ImagickException: Failed to read the file in ...

我正在运行OS X,Brew,PHP 7.0,Php70-Imagick-头,ImageMagick-与ghostscript,Ghostscript

命令行测试正常工作:

convert 1.pdf 1.jpg

文件权限还可以。试试带有真实路径函数的URL和本地文件,因此FilePath也可以。如果打开JPEG。

脚本正常工作。
phpinfo() -> ImageMagick supported formats: EPDF, PDF, PDFA, etc.

更新:已解决。下面的解决方案。

这个问题与Ghostscript的路径有关。它位于"/usr/local/bin"中,但是Apache无法使用此路径。(phpinfo-> apache环境 ->路径)

解决方案是符合文件到另一个路径:

 sudo ln -s /usr/local/bin/gs /usr/bin/gs

OS X El Capitan注意!/usr/bin/in OS X 10.11 受到保护。您必须遵循此步骤:

1. Reboot to Recovery Mode. Reboot and hold "Cmd + R" after start sound.
2. In Recovery Mode go to Utilities -> Terminal.
3. Run: csrutil disable
4. Reboot in Normal Mode.
5. Do the "sudo ln -s /usr/local/bin/gs /usr/bin/gs" in terminal.
6. Do the 1 and 2 step. In terminal enable back csrutil by run: csrutil enable

这是更新OS X上Apache Path变量的更好方法,该变量不需要符合链接(因此无需禁用SIP):

https://www.euperia.com/wrote/solved-php-php-imagick-unap--unap-to-open-image-pdf/

相关内容

最新更新