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

鑫鑫
阅读 277 标签:php  

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

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

imagick 插件报错的代码

if(!extension_loaded('imagick')){
            return_json(1, '模块加载失败',[$pdf]);
        }
        if(!file_exists($pdf)){
            return_json(1, '文件路径不正确');
        } 
        $path = $this->file_path( $path1);
        try{
            $im = new Imagick();

            $im->setCompressionQuality(100);


            $im->setResolution(120, 120);//设置分辨率 值越大分辨率越高

            $im->readImage($pdf); //报错这一行
        }catch (Exception $e) {

            return_json(1,  $e->getMessage(),[$pdf]);
        }

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

文章来源:网络 版权归原作者所有,如涉及知识产权问题,请权利人联系我们,我们将立即处理.
标签: php
鑫鑫
文章 48 获得 0个赞 共 0个粉丝

推荐阅读 更多精彩内容