Page 1 of 1

Errors when used from PHP, not from Terminal?

Posted: 2011-01-11T05:19:38-07:00
by gazchap
I have a script that is supposed to take the first page of a PDF file and generate a thumbnail of it.

I'm running ImageMagick 6.6.5-0 2010-10-14 Q16 on a CentOS system, and I have Ghostscript installed also.

The weird thing is, the command doesn't work when run from within PHP's exec() function. The error messages returned are:

Code: Select all

convert: no decode delegate for this image format `/tmp/magick-XX0ORHI2' @ error/constitute.c/ReadImage/532.
convert: missing an image filename `jpg:/home/sfocus/public_html/test.jpg' @ error/convert.c/ConvertImageCommand/2946.
Yet when I run the same command directly from a shell window (logged in as the relevant user) the command works fine.

The command being executed is:

Code: Select all

/usr/local/bin/convert -colorspace RGB -thumbnail "106x150>" "/home/sfocus/public_html/assets/back_issues/2010/2010_07.pdf[0]" miff:- | /usr/local/bin/composite -compose Over -gravity "Center" - -size "106x150" "xc:#FFFFFF" miff:- | /usr/local/bin/convert -thumbnail "106x150>" - jpg:-

Re: Errors when used from PHP, not from Terminal?

Posted: 2011-01-11T17:47:10-07:00
by anthony
PHP runs in a different environment with posibly different command PATH, working directory, and permissions. Somtimes even as a different user entirely!

That is what is going wrong.

See IM Examples, PHP, with IM shell commands
http://www.imagemagick.org/Usage/api/#php

Re: Errors when used from PHP, not from Terminal?

Posted: 2011-01-12T08:58:52-07:00
by gazchap
Thanks for the link Anthony, but I don't think this is the whole story, as it were.

Other ImageMagick commands (that don't involve PDF files) work fine from within PHP, it's just this one that is generating these decode errors.

Could that be permissions issues with various Ghostscript libraries, perhaps?

Re: Errors when used from PHP, not from Terminal?

Posted: 2011-01-12T11:18:47-07:00
by fmw42
Does PHP know where ghostscript is installed? Do you have current versions of IM and Ghostscript? Might you have multiple versions of IM and/or Ghostscript installed such that there is now some confusion on which one to use in each situation?

Re: Errors when used from PHP, not from Terminal?

Posted: 2011-01-12T17:57:03-07:00
by anthony
It may be that the coder can not find the ghostscript library or delegate commands.
That is ghostscript is not accessible directly from the PHP environment.

Re: Errors when used from PHP, not from Terminal?

Posted: 2011-01-13T04:51:56-07:00
by gazchap
Cheers guys.

Turned out that the path to gs wasn't in the system PATH variable, and the version of Apache we're using has some sort of weird bug in it where the PATH variable is reset to something else and can't be changed. Annoying.

Nevertheless, I've edited the delegates.xml file for IM to point it to the correct directory for gs, so it's all working now :)