Why would ImageMagick & Ghostscript work in CMD but not in PHP?

Viewed 41

We are migrating from a Windows 2012 Server to a Windows 2019 server. We have been using ImageMagick as Imagick in PHP and Ghostscript to convert PDF files into JPG files for quite some time without issue, but now on the new server it will not work. This is the error message we receive:

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 "-r300x300" -dPrinted=false -dFirstPage=1 -dLastPage=1 "-sOutputFile=C:/Windows/TEMP/magick-mkMmFi8vXckWEAzjPQWNNyAeLCmErcUI%d" "-fC:/Windows/TEMP/magick-RHvJ0K3gv-gkEMBSrS8cft5IBz4k5e3f" "-fC:/Windows/TEMP/magick-YHH7fNU9o9vL3dni8YuaJxpvgDWi04hK"' (The system cannot find the file specified. ) @ error/delegate.c/ExternalDelegateCommand/516 in C:\inetpub\vhosts\example.com\httpdocs\crons\test.php:1214 Stack trace: #0 C:\inetpub\vhosts\example.com\httpdocs\crons\test.php(1214): Imagick->readImage() #1 {main} thrown in C:\inetpub\vhosts\example.com\httpdocs\crons\test.php on line 1214

We have ImageMagick 7.1.0 installed, Ghostscript 10, and the PHP extension added for Imagick along with the necessary files.

Here is what we have already tried...

  1. ImageMagick and Ghostscript paths are both in the Environmental Variables.
  2. Modified the Delegates.xml for ImageMagick with full path to Ghostscript.
  3. Modified the Policy.xml for ImageMagick to uncomment PDF domain module, including adding "read|write", as well as uncommenting the temporary-path line.
  4. Verified the Ghostscript registery keys exist and point to the correct paths.
  5. Verified all directories had the necessary permissions.

As well as probably some other things we are just forgetting. None of those steps were necessary on the old server.

It DOES work as expected when run from command line as

magick test.pdf test.png

But it will not work when run from PHP.

At this point we are completely stumped. We have been searching and trying suggestions for hours, but nothing seems to work. If anyone has gotten this working and we are just missing something, advice would be so greatly appreciated.

EDIT

I forgot to mention we are running PHP 7.4.3 and everything is 64bit (Windows, IIS, PHP, ImageMagick, Ghostscript).

We can also use exec("gswin64c --help", $array); in PHP to display info about Ghostscript with no errors. So the issue is just that the PHP imagick extension can't seem to access Ghostscript.

0 Answers
Related