Imagick不会打开"无法读取文件"异常的pdf文件

ole*_*leg 8 php pdf imagemagick imagick php-7

试图从php脚本打开PDF文件会出现错误:

Uncaught ImagickException: Failed to read the file in ...
Run Code Online (Sandbox Code Playgroud)

我正在运行OS X,Brew,PHP 7.0,php70-imagick --HEAD,ImageMagick --with-ghostscript,GhostScript

命令行测试工作正常:

convert 1.pdf 1.jpg
Run Code Online (Sandbox Code Playgroud)

文件权限没问题.尝试使用具有realpath功能的URL和本地文件,因此filepath也可以.如果打开jpeg,脚本工作正常.

phpinfo() -> ImageMagick supported formats: EPDF, PDF, PDFA, etc.
Run Code Online (Sandbox Code Playgroud)

更新:解决了.解决方法如下

ole*_*leg 17

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

解决方法是将符号链接文件转换为另一个路径:

 sudo ln -s /usr/local/bin/gs /usr/bin/gs
Run Code Online (Sandbox Code Playgroud)

OS X El Capitan注意!/ usr/bin /在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
Run Code Online (Sandbox Code Playgroud)