Imagick don't open pdf files with “Failed to read the file” exception

守給你的承諾、 提交于 2019-12-01 00:52:04

问题


Trying to open PDF file from php script drop into fault with error:

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

I'm running OS X, Brew, PHP 7.0, php70-imagick --HEAD, ImageMagick --with-ghostscript, GhostScript

Command line test works fine:

convert 1.pdf 1.jpg

File permission is ok. Try both, an URL and local file with realpath function, so filepath is ok too. Script works fine if open jpeg.

phpinfo() -> ImageMagick supported formats: EPDF, PDF, PDFA, etc.

UPDATE: Solved. Solution below.


回答1:


This problem was with path to ghostscript. It's locate in "/usr/local/bin", but this path is not available to Apache. (phpinfo -> Apache Environment -> PATH)

Solution is to symlink file to another path:

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

OS X El Capitan Note! /usr/bin/ in OS X 10.11+ is protected. You have to follow this steps:

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



回答2:


Here is an better way of updating the Apache path variable on OS X which doesn't require symlinking (and therefore no need to disable SIP):

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



来源:https://stackoverflow.com/questions/37927247/imagick-dont-open-pdf-files-with-failed-to-read-the-file-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!