manually set delegate path to gs (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?".
imarcw

manually set delegate path to gs (ghostscript)

Post by imarcw »

I'm using IM to convert both PDFs and image files to JPEG. I have IM and ghostscript installed on Mac OS X using MacPorts and everything works fine in Terminal, with PDFs or otherwise.

I tried to call the convert command using AppleScript's "do shell script" command and "convert" wasn't recognized. Thanks to the following Apple developer note, I realized that AppleScript just needed the path to IM to be explicitly set, so instead of convert, I used /opt/local/bin/convert.

http://developer.apple.com/technotes/tn2002/tn2065.html

Problem partially solved. Now I'm finding that when using IM within AppleScript on PDFs, it has the same problem finding the gs command, only I don't know how to specify the path because I'm not calling gs directly.

This is just a shot in the dark, but I'm looking at /opt/local/lib/ImageMagick-6.5.4/config/delegates.xml and wondering if the following line (or another one like it) can be edited somehow to include the full path to gs:

<delegate decode="pdf" encode="eps" mode="bi" command=""gs&quot; -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i""/>

If so, what is the exact language needed (I already know the path is /opt/local/bin/gs), and if not, what else can I do?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: manually set delegate path to gs (ghostscript)

Post by magick »

You specify an absolute path. Find out where gs is located and substitute it in the delegates.mgk configuration file (i.e. "/opt/local/bin/gs");
imarcw

Re: manually set delegate path to gs (ghostscript)

Post by imarcw »

That worked, just as I speculated it might. Thanks!
fantomas

Re: manually set delegate path to gs (ghostscript)

Post by fantomas »

I read above three messages about 10 times, my logic device gives up :)
So where can I set path to GS? Having no any delegates.mgk file.

UPD. Oh, I'm blind. Now see the BOLD ""gs"" in first message )
devnul

Re: manually set delegate path to gs (ghostscript)

Post by devnul »

I was having a similar problem (though building ImageMagic from source code) and based on my reading of the configure shell script, this worked for me:

PSDelegate=/usr/local/ghostscript/bin/gs ./configure --prefix=/usr/local/ImageMagick-6.5.4-2 --with-frozenpaths

Hope this helps someone.

- dEvNuL
AusS2000
Posts: 32
Joined: 2012-03-16T22:12:53-07:00
Authentication code: 8675308

Re: manually set delegate path to gs (ghostscript)

Post by AusS2000 »

This looks like exactly my problem but unfortunately the paths/config files aren't the same.

I am triggering PDF>JPG 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 it from the middleware it doesn't.

I assume this solution involves telling ImageMagick where to find Ghostscript.

I have ImageMagic 6.9.3-6 and Ghostscript 9.19 installed but the directories/files are different.

There is no '/opt/local/bin/g's. There is a file '/usr/local/bin/gs'.

I did a 'locate delegates.xml':
/usr/local/Cellar/imagemagick/6.9.3-6/etc/ImageMagick-6/delegates.xml
/usr/local/Cellar/imagemagick/6.9.3-6/share/doc/ImageMagick-6/www/source/delegates.xml
/usr/local/etc/ImageMagick-6/delegates.xml < is an alias or symbolic link to the first occurrence

I have edited all reference to gs to include the path:
"/usr/local/bin/gs"

Still no go.

And the hardest thing is how do I debug this? Is there a console somewhere where I can see the script calling imagemagick and imagemagick calling ghostscript and what the errors are?
AusS2000
Posts: 32
Joined: 2012-03-16T22:12:53-07:00
Authentication code: 8675308

Re: manually set delegate path to gs (ghostscript)

Post by AusS2000 »

Ok, so I do see an error in the Console:
4/18/16 3:22:56.876 PM sudo[69157]: username : TTY=unknown ; PWD=/Applications/TeraScript Server 7/log_TeraScript_Server_7 ; USER=username ; COMMAND=/opt/local/bin/convert -thumbnail 215x300 /Library/Server/Web/Data/Sites/~bartel/brochures/files/EV-FD-6770-3292A.pdf[0] -flatten /Library/Server/Web/Data/Sites/~bartel/brochures/images/EV-FD-6770-3292A.jpg
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: manually set delegate path to gs (ghostscript)

Post by snibgo »

In the IM command, "-verbose" will show you the command IM is using to run Ghostscript. "-debug all" gives information on how it makes that command, by reading delegates.xml.
snibgo's IM pages: im.snibgo.com
AusS2000
Posts: 32
Joined: 2012-03-16T22:12:53-07:00
Authentication code: 8675308

Re: manually set delegate path to gs (ghostscript)

Post by AusS2000 »

Thanks for that. I can really see a lot of what is going on. Unfortunately so far I have only been able to see results for the Command Line version, which is successful. I have not been able to view results for the script driven version which is not. I will look into piping the results to a text file if that is possible.
AusS2000
Posts: 32
Joined: 2012-03-16T22:12:53-07:00
Authentication code: 8675308

Re: manually set delegate path to gs (ghostscript)

Post by AusS2000 »

I added ' 2>error.txt' to the command in the script and managed to capture some information. It's fairly longwinded but I located the first mention of gs and copied from there on down:

2016-04-19T12:56:19+10:00 0:00.060 0.040u 6.9.3 Policy convert[89262]: policy.c/IsRightsAuthorized/574/Policy
Domain: Delegate; rights=Execute; pattern="/usr/local/bin/gs" ...
"/usr/local/bin/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-892621OchGEQb8gT8%d" "-f/var/tmp/magick-89262EysDvvpKoL3W" "-f/var/tmp/magick-89262wrsSJraORuPz"
2016-04-19T12:56:20+10:00 0:01.060 0.040u 6.9.3 Locale convert[89262]: locale.c/GetLocaleOptions/825/Locale
Searching for locale file: "/usr/local/Cellar/imagemagick/6.9.3-6/share/ImageMagick-6/locale.xml"
2016-04-19T12:56:20+10:00 0:01.060 0.040u 6.9.3 Locale convert[89262]: locale.c/GetLocaleOptions/825/Locale
Searching for locale file: "/usr/local/Cellar/imagemagick/6.9.3-6/lib/ImageMagick//config-Q16/locale.xml"
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Locale convert[89262]: locale.c/GetLocaleOptions/825/Locale
Searching for locale file: "/usr/local/Cellar/imagemagick/6.9.3-6/etc/ImageMagick-6/locale.xml"
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Locale convert[89262]: locale.c/GetLocaleOptions/825/Locale
Searching for locale file: "/usr/local/Cellar/imagemagick/6.9.3-6/share/doc/ImageMagick-6/locale.xml"
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Locale convert[89262]: locale.c/GetLocaleOptions/825/Locale
Searching for locale file: "/Users/wayneirvine/.config/ImageMagick/locale.xml"
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Locale convert[89262]: locale.c/GetLocaleOptions/825/Locale
Searching for locale file: "/Users/wayneirvine/.magick/locale.xml"
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Configure convert[89262]: locale.c/LoadLocaleCache/1176/Configure
Loading locale configure file "/usr/local/Cellar/imagemagick/6.9.3-6/share/ImageMagick-6/locale.xml" ...
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Locale convert[89262]: locale.c/GetLocaleOptions/825/Locale
Searching for locale file: "/usr/local/Cellar/imagemagick/6.9.3-6/share/ImageMagick-6/english.xml"
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Locale convert[89262]: locale.c/GetLocaleOptions/825/Locale
Searching for locale file: "/usr/local/Cellar/imagemagick/6.9.3-6/lib/ImageMagick//config-Q16/english.xml"
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Locale convert[89262]: locale.c/GetLocaleOptions/825/Locale
Searching for locale file: "/usr/local/Cellar/imagemagick/6.9.3-6/etc/ImageMagick-6/english.xml"
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Locale convert[89262]: locale.c/GetLocaleOptions/825/Locale
Searching for locale file: "/usr/local/Cellar/imagemagick/6.9.3-6/share/doc/ImageMagick-6/english.xml"
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Locale convert[89262]: locale.c/GetLocaleOptions/825/Locale
Searching for locale file: "/Users/wayneirvine/.config/ImageMagick/english.xml"
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Locale convert[89262]: locale.c/GetLocaleOptions/825/Locale
Searching for locale file: "/Users/wayneirvine/.magick/english.xml"
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Configure convert[89262]: locale.c/LoadLocaleCache/1176/Configure
Loading locale configure file "/usr/local/Cellar/imagemagick/6.9.3-6/share/ImageMagick-6/english.xml" ...
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Exception convert[89262]: delegate.c/ExternalDelegateCommand/483/Exception
FailedToExecuteCommand `"/usr/local/bin/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-892621OchGEQb8gT8%d" "-f/var/tmp/magick-89262EysDvvpKoL3W" "-f/var/tmp/magick-89262wrsSJraORuPz"' (-1)
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Resource convert[89262]: resource.c/RelinquishUniqueFileResource/1042/Resource
Relinquish /var/tmp/magick-89262EysDvvpKoL3W
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Exception convert[89262]: utility.c/ShredFile/1822/Exception
Failed to remove: /var/tmp/magick-89262EysDvvpKoL3W.cache
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Resource convert[89262]: resource.c/RelinquishUniqueFileResource/1042/Resource
Relinquish /var/tmp/magick-89262wrsSJraORuPz
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Exception convert[89262]: utility.c/ShredFile/1822/Exception
Failed to remove: /var/tmp/magick-89262wrsSJraORuPz.cache
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Resource convert[89262]: resource.c/RelinquishUniqueFileResource/1042/Resource
Relinquish /var/tmp/magick-892621OchGEQb8gT81
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Exception convert[89262]: utility.c/ShredFile/1822/Exception
Failed to remove: /var/tmp/magick-892621OchGEQb8gT81.cache
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Cache convert[89262]: cache.c/DestroyPixelCache/999/Cache
destroy
2016-04-19T12:56:20+10:00 0:01.060 0.060u 6.9.3 Exception convert[89262]: convert.c/ConvertImageCommand/3252/Exception
no images defined `/Library/Server/Web/Data/Sites/~bartel/brochures/images/SI-7EA0A-002-00-Eng_v1_m56577569830759287.jpg'
convert: FailedToExecuteCommand `"/usr/local/bin/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-892621OchGEQb8gT8%d" "-f/var/tmp/magick-89262EysDvvpKoL3W" "-f/var/tmp/magick-89262wrsSJraORuPz"' (-1) @ error/delegate.c/ExternalDelegateCommand/483.
convert: no images defined `/Library/Server/Web/Data/Sites/~bartel/brochures/images/SI-7EA0A-002-00-Eng_v1_m56577569830759287.jpg' @ error/convert.c/ConvertImageCommand/3252.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: manually set delegate path to gs (ghostscript)

Post by snibgo »

You have:

Code: Select all

convert: FailedToExecuteCommand `"/usr/local/bin/gs"... @ error/delegate.c
This is the path in which you found gs. And the convert command works at the command-line. You could check the gs command at the command line. I suspect that will also work (after you have replaced the temporary filenames).

Perhaps the problem is permissions. Does everyone have permission to run gs?
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: manually set delegate path to gs (ghostscript)

Post by fmw42 »

OMMAND=/opt/local/bin/convert -thumbnail 215x300 /Library/Server/Web/Data/Sites/~bartel/brochures/files/EV-FD-6770-3292A.pdf[0] -flatten /Library/Server/Web/Data/Sites/~bartel/brochures/images/EV-FD-6770-3292A.jpg
You might try using proper IM 6 syntax and read the input image before applying processing functions such as -thumbnail and -flatten.
AusS2000
Posts: 32
Joined: 2012-03-16T22:12:53-07:00
Authentication code: 8675308

Re: manually set delegate path to gs (ghostscript)

Post by AusS2000 »

snibgo wrote:You have:
Perhaps the problem is permissions. Does everyone have permission to run gs?
I check permissions this morning and gave everyone permission to run gs.

I'll also try running gs directly.
Last edited by AusS2000 on 2016-04-18T21:19:16-07:00, edited 1 time in total.
AusS2000
Posts: 32
Joined: 2012-03-16T22:12:53-07:00
Authentication code: 8675308

Re: manually set delegate path to gs (ghostscript)

Post by AusS2000 »

fmw42 wrote:
OMMAND=/opt/local/bin/convert -thumbnail 215x300 /Library/Server/Web/Data/Sites/~bartel/brochures/files/EV-FD-6770-3292A.pdf[0] -flatten /Library/Server/Web/Data/Sites/~bartel/brochures/images/EV-FD-6770-3292A.jpg
You might try using proper IM 6 syntax and read the input image before applying processing functions such as -thumbnail and -flatten.
Has syntax changed? This has always worked previously (and still does on the dev server). Is syntax different for 6.9.3-6?

I'll revisit the command syntax but any pointers you can provide would be appreciated.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: manually set delegate path to gs (ghostscript)

Post by fmw42 »

Imagemagick does not follow normal unix command syntax. You need to put the image right after convert (unless it is a vector format), then put the settings and then the operators. IM 6 is somewhat forgiving, but may falter if not proper syntax. IM 7 will be much less forgiving. See http://www.imagemagick.org/Usage/basics/#cmdline
Post Reply