imagick插件如何使用readImage报错 Failed to read the file 的如何解决方法

夕阳是如此的美丽。太阳改变了颜色,火红火红的,没有了中午的那份狂躁与炽热,从远处向它看去,斜晖洒在脸上,脸便立即变成了红褐色,感觉就像是一个慈祥的老人深情的摸着你的头,亲切而又温暖。

在使用php的imagick插件生成文件的缩图时,发现报错" Failed to read the file",检查了下服务器配置,虽然很快的解决了,但为了防止以后遇到相同的情况,就记录下解决过程。

imagick插件报错"Failed to read the file"场景

imagick插件报错的代码

$paf = 'xxx.pdf';
$im = new Imagick();  
$im->setResolution(120,120);  
$im->setCompressionQuality(100);
$im->readImage($pdf."[0]");  //报错的一行
..........

imagick 插件在使用 readImage 报如下的错误!

Failed to read the file

imagick使用readImage报错 Failed to read the file 的解决方法

1、安装 ghostscript 

我个人的服务器是 centos 系统,执行下面的ssh命令,安装 ghostscript 即可。

ghostscript ssh 安装命令

sudo yum install ghostscript

如果你的服务器系统不是centos 可以使用下面的命令

sudo apt-get install ghostscript

imagick使用readImage报错 Failed to read the file 的解决方法

2、修改 php-fpm.conf 文件

如果安装 ghostscript 后依然报错,那么可以尝试修改 php-fpm.conf 文件。

(1)、找到并打开 php-fpm.conf 文件

如下图,下面的截图来自宝塔面板:

找到并打开 php-fpm.conf 文件

(2)、找到如下的代码:

env[PATH] = /usr/local/bin:/usr/bin:/bin

找到并打开 php-fpm.conf 文件

并去掉代码前面的注释,如果没有此代码,可以在文件未尾加上。

到此这篇关于imagick插件如何使用readImage报错 Failed to read the file 的如何解决方法就介绍到这了。灰心生失望,失望生动摇,动摇生失败。更多相关imagick插件如何使用readImage报错 Failed to read the file 的如何解决方法内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
php get_magic_quotes_gpc()函数介绍与用法

php取消运行时间限制的方法

php中ini_set函数介绍

php获取文件夹下所有文件/文件夹

php如何实现文件下载的方法