Page 1 of 1

Issue working with ImageMagick and Ghostscript

Posted: 2016-04-19T18:47:18-07:00
by AusS2000
I am triggering PDF>JPG conversion through Terascript (middleware) calling a shell script. If I construct the command manually and enter it on the command line it works. If I trigger the same command from the middleware it doesn't.

Code: Select all

sudo -u username -p password /opt/local/bin/convert -thumbnail 215x300 /file/path/source.pdf[0] -flatten /file/path/target.jpg
Environment is Mac OS X 10.10.5 Yosemite, Apache 2.4, Terascript 7, ImageMagick 6.9.3-6, Ghostscript 9.19.

Surprisingly this set up has been working for years on Mac OS X 10.7.5 Lion, Apache 2.2, Terascript 6.21, ImageMagick 6.7.6-0, Ghostscript 9.05.

I can confirm that ImageMagick is running fine and can resize images. The error occurs when calling gs (Ghostscript). The error is:

Code: Select all

convert: FailedToExecuteCommand `"/usr/local/bin/gs"... @ error/delegate.c
Things I have tried are:
Edit the delegates.xml file to include an absolute reference to gs (/usr/local/bin/gs).
Changing permissions so Everyone has Execute privileges for gs.
Running gs directly from the script (works, but doesn't answer the question)

Things I am yet to try:
Checking the command syntax. Apparently it shouldn't have changed much between these versions but will in future.

Re: Issue working with ImageMagick and Ghostscript

Posted: 2016-04-19T19:31:41-07:00
by snibgo
I'll mention that "-thumbnail" is an operation, so it should come after the input file, not before it. Your syntax will fail under IM v7 magick.

I doubt that this is causing "FailedToExecuteCommand".

Re: Issue working with ImageMagick and Ghostscript

Posted: 2016-04-19T19:56:51-07:00
by fmw42
Try exporting your path to IM convert and/or your path to GS before the sudo command. If your middleware is like Applescript do shell script, then that technique works. See viewtopic.php?f=1&t=14213&p=132176&hili ... pt#p132176

Code: Select all

export PATH=/opt/local/bin:/path2gs_folder:$PATH; convert /file/path/source.pdf[0] -thumbnail 215x300 -flatten /file/path/target.jpg
Also read your input file before applying operators such as -thumbnail and -flatten

Re: Issue working with ImageMagick and Ghostscript

Posted: 2016-04-19T20:21:57-07:00
by AusS2000
Ok, I re-ordered the command with the source file path before the operation and looked up what PATH is (new to me).

As I understand, it is a list of paths the try to locate files called during execution.

So in my case it would be:
export PATH=/opt/local/bin:/usr/local/bin:$PATH; convert /file/path/source.pdf[0] -thumbnail 215x300 -flatten /file/path/target.jpg

Should I then remove the absolute references from the delegates.xml file? It looks like I am trying to do the same thing twice.

Re: Issue working with ImageMagick and Ghostscript

Posted: 2016-04-19T21:27:45-07:00
by fmw42
Looks like IM and GS are in the same locations, so only one would be needed. You should still reference the paths to your images and if the following does not work, add the path to convert as well, though I don't think that will help.

Code: Select all

export PATH=/usr/local/bin:$PATH; convert /file/path/source.pdf[0] -thumbnail 215x300 -flatten /file/path/target.jpg
If this does not fix the issue, then I am at a loss. The above works for me when using Applescript and do shell script. However, it works fine without all the PATH and export if you command the terminal app to run your script. See the post I linked to above.