宝塔安装imagick pdf转图片报错 Fatal error: Uncaught ImagickException: FailedToExecuteCommand `'gs'
php 实现pdf轩图片,需要安装 imagick 扩展,过程遇到了许多坑
1 从宝塔中找软件商店-》php7.2 安装 imagemagick
2 .查看是否已安装成功
phpinfo();
看到 imagick 说明安装成功了
3 安装成功后php引用测试
error_reporting(E_ALL | E_STRICT); if (!extension_loaded('imagick')) { //判断是否安装成功 return false; } $im = new \Imagick(); $im->setResolution(120, 120); $im->setCompressionQuality(100); $im->readImage('./jl.pdf');
发现报错
Fatal error: Uncaught ImagickException: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r120x120' -dPrinted=false '-sOutputFile=/tmp/magick-l0e-FhSxrXhKm2cTlBQvPiprzQbFGNc0%d' '-f/tmp/magick-zeTs6dTm6x80rx-VgRoLgOJJ79cd1VS4' '-f/tmp/magick-N5U8Cf6BSOtsmqeOpKG3zTHQk6Jep5y9'' (32512) @ error/ghostscript-private.h/ExecuteGhostscriptCommand/74 in /www/wwwroot/book.51zuso.com/test.php:17 Stack trace: #0 /www/wwwroot/book.51zuso.com/test.php(17): Imagick->readimage() #1 {main} thrown in
这个报错,百度上找了很多,说是环境量问题,测试了很久都不对
我最终解决是安装ghostscript 才不会报错
yum install ghostscript
经过测试发现 宝塔php7.4的,安装了ghostscript 依然报错,为找到问题,因此用php7.2的
若要手动安装,参考这篇文章
https://blog.csdn.net/liangxun0712/article/details/79584016