Errors when used from PHP, not from Terminal?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
gazchap
Posts: 6
Joined: 2009-03-01T02:58:21-07:00

Errors when used from PHP, not from Terminal?

Post 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:-
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
gazchap
Posts: 6
Joined: 2009-03-01T02:58:21-07:00

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

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
gazchap
Posts: 6
Joined: 2009-03-01T02:58:21-07:00

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

Post 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 :)
Post Reply