Imagick 不打开带有 "Failed to read the file" 异常的 pdf 文件
Imagick don't open pdf files with "Failed to read the file" exception
尝试从 php 脚本打开 PDF 文件时遇到错误:
Uncaught ImagickException: Failed to read the file in ...
我是 运行 OS X, Brew, PHP 7.0, php70-imagick --HEAD, ImageMagick --with-ghostscript, GhostScript
命令行测试工作正常:
convert 1.pdf 1.jpg
文件权限没问题。尝试两者,一个 URL 和具有 realpath 功能的本地文件,所以文件路径也可以。如果打开 jpeg,脚本工作正常。
phpinfo() -> ImageMagick supported formats: EPDF, PDF, PDFA, etc.
更新:已解决。解决方案如下。
这个问题与 ghostscript 的路径有关。它位于“/usr/local/bin”,但此路径对 Apache 不可用。 (phpinfo -> Apache 环境 -> PATH)
解决方案是将文件符号链接到另一个路径:
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 路径变量的更好方法,它不需要符号链接(因此不需要禁用 SIP):
https://www.euperia.com/wrote/solved-php-imagick-unable-to-open-image-pdf/
尝试从 php 脚本打开 PDF 文件时遇到错误:
Uncaught ImagickException: Failed to read the file in ...
我是 运行 OS X, Brew, PHP 7.0, php70-imagick --HEAD, ImageMagick --with-ghostscript, GhostScript
命令行测试工作正常:
convert 1.pdf 1.jpg
文件权限没问题。尝试两者,一个 URL 和具有 realpath 功能的本地文件,所以文件路径也可以。如果打开 jpeg,脚本工作正常。
phpinfo() -> ImageMagick supported formats: EPDF, PDF, PDFA, etc.
更新:已解决。解决方案如下。
这个问题与 ghostscript 的路径有关。它位于“/usr/local/bin”,但此路径对 Apache 不可用。 (phpinfo -> Apache 环境 -> PATH)
解决方案是将文件符号链接到另一个路径:
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 路径变量的更好方法,它不需要符号链接(因此不需要禁用 SIP):
https://www.euperia.com/wrote/solved-php-imagick-unable-to-open-image-pdf/