Issue working with ImageMagick and Ghostscript

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
AusS2000
Posts: 32
Joined: 2012-03-16T22:12:53-07:00
Authentication code: 8675308

Issue working with ImageMagick and Ghostscript

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Issue working with ImageMagick and Ghostscript

Post 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".
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Issue working with ImageMagick and Ghostscript

Post 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
AusS2000
Posts: 32
Joined: 2012-03-16T22:12:53-07:00
Authentication code: 8675308

Re: Issue working with ImageMagick and Ghostscript

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

Re: Issue working with ImageMagick and Ghostscript

Post 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.
Post Reply