0

I'm trying this code in PHP to create a preview image of a PDF file and I'm getting this error.

if ($imgfiletype == 'pdf'){
                $im = new imagick($file_path.'[0]');
                $im->setImageFormat('jpg');
                header('Content-Type: image/jpeg');
                echo $im;
            }

Fatal error : Uncaught ImagickException: FailedToExecuteCommand `'gs' -q -dQUIET...

I know it's something with ghostscript, but it is installed on the server.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
puluku
  • 1
  • 1
  • it seems that the command `gs` fails for some reason, but can you share the complete error output and maybe try running the complete command by hand in the terminal/cli and see there for a more detailed error message – DaGhostman Dimitrov Apr 11 '20 at 17:00
  • Often, the issue is that PHP uses different ENV variables that the OS. So the solution for that is to edit your Imagemagick delegates.xml file to put the full path to `gs` in the PS commands for PDF. The other possible issue is that the policy.xml file needs to have permission to read PDF files. See https://stackoverflow.com/questions/52861946/imagemagick-not-authorized-to-convert-pdf-to-an-image/52863413#52863413 – fmw42 Apr 11 '20 at 17:13

0 Answers0