Reputation: 236
I've installed the ImageMagick PHP extension on a MAC via pecl. it's showing up under phpinfo(), and lists PDF as a supported format.
I'm trying to read in a PDF and convert it to an image. However the constructor throws an exception when the source is a PDF. Image files work successfully.
$im = new imagick('TestDoc.pdf[0]'); // Throws Exception when PDF specified.
//$im = new imagick('TestImage.png'); // Succeeds.
$im->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $im;
Fatal error: Uncaught exception 'ImagickException' with message 'FailedToExecuteCommand
`"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -
dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4
"-r72x72" -dFirstPage=1 -dLastPage=1 "-sOutputFile=/var/tmp/magick-43594XlaRxeGWg1ps%d" "-
f/var/tmp/magick-43594O_WVqnAJTgzr" "-f/var/tmp/magick-43594ivJ_pKBcF3s7"' (-1) @
error/utility.c/SystemCommand/2029' in
/Users/garys/Documents/Projects/accrivia/code/test/test.php:8 Stack trace: #0
/Users/garys/Documents/Projects/accrivia/code/test/test.php(8): Imagick-
>__construct('../TestDoc.pdf[...') #1 {main} thrown in
/Users/garys/Documents/Projects/accrivia/code/test/test.php on line 8
The tmp file mentioned in the output is created, but is 0 bytes. If I execute the full 'gs' command in the message (using actual files) on the command line, it works successfully.
ImageMagick and GhostScript were installed with brew.
In PHP, system('echo $PATH'); gives /usr/bin:/bin:/usr/sbin:/sbin 'gs' is in /usr/bin/
Does anyone have a suggestion. A web search for the exception message turns up nothing specific.
Many thanks Gary.
Upvotes: 6
Views: 6422
Reputation: 1097
I had the same problem on MacOS High Sierra, PHP 7.0 installed from Homebrew. The problem is that FPM $PATH
contains (as echoed by <php echo getenv('PATH'); ?>
) /usr/bin:/bin:/usr/sbin:/sbin
, which doesn't include Brew's /usr/local/bin/
install path.
To solve I added
env[PATH] = /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
to /usr/local/etc/php/7.0/php-fpm.d/www.conf
, restarted php70 and worked! On Homebrew's forums @comes suggested to add the same to .env
file
Upvotes: 0
Reputation: 19
Never used imageMagick myself but the documents says it needs GhostScript to read the PDF documents
PDF support : Requires Ghostscript to read.
EDIT: Have you checked that GhostScript is working?
Upvotes: 3