Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Uncaught exception 'ImagickException' with message 'FailedToExecuteCommand'

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.

like image 579
Gary Avatar asked Jun 19 '14 04:06

Gary


1 Answers

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?

like image 189
SinisterGlitch Avatar answered Oct 28 '22 13:10

SinisterGlitch