Page 1 of 2

Errors from convert when IM invoked from IDL

Posted: 2014-02-26T15:59:22-07:00
by blesht
I am not sure that I have the correct forum, if not, I apologize. If nothing else, I'm hoping someone can help me interpret the error messages I'm seeing and perhaps point me to the correct place to discuss them and correct the problem.

I have IM6.8.8.4-1 running on a Macintosh under OSX10.8.5. I also have ghostscript9.10 installed. I am trying to convert a postscript file to a png file from within IDLv8.2.3 (a MATLAB-like programming language). IDL has a SPAWN command that passes its argument to the shell for execution. For instance:

IDL> SPAWN, 'convert --version'
Version: ImageMagick 6.8.8-4 Q16 x86_64 2014-02-26 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC HDRI Modules
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms ltdl lzma openexr png rsvg tiff webp wmf x xml zlib

However,
IDL> SPAWN, 'convert newtest.ps newtest3.png' results in
convert-Q16: bad parameters to zlib `/var/tmp/magick-80233e81viV9KI1RG1' @ error/png.c/MagickPNGErrorHandler/1804.
convert-Q16: corrupt image `/var/tmp/magick-80233e81viV9KI1RG1' @ error/png.c/ReadPNGImage/4074.
convert-Q16: Postscript delegate failed `newtest.ps': No such file or directory @ error/ps.c/ReadPSImage/837.
convert-Q16: no images defined `newtest3.png' @ error/convert.c/ConvertImageCommand/3147.

When run directly from the shell, convert works exactly as expected.
bash-3.2$ convert newtest.ps newtest2.png
bash-3.2$

Is there anything in the error message that would help me understand why the IM is failing when invoked from IDL?

Thank you.

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-26T16:02:23-07:00
by fmw42
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms ltdl lzma openexr png rsvg tiff webp wmf x xml zlib
IM is not finding Ghostscript or it is not installed properly, otherwise it would show in the list above from convert -version including gslib.

Did you reinstall IM after installing GS?

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-26T16:07:07-07:00
by blesht
Thank you for the quick reply. Yes, I had ghostscript installed (via Fink) before I installed ImageMagick (also via Fink). I certainly can try uninstalling and reinstalling, but I've been through that exercise before. Is there some way I can force ImageMagick to find ghostscript?

IDL> spawn, 'which gs'
/sw/bin/gs
IDL> spawn, 'gs --version'
9.10
IDL>

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-26T16:20:55-07:00
by fmw42
Not that I know about. But I am not an expert on unix or installations. You can check out http://www.imagemagick.org/script/advan ... lation.php

Look at your config.log file (in the downloaded IM folder). It should tell you there was an error installing GS and perhaps what the issue might be. You might also see if you can find an error message from your install of GS. It might be as simple as not having installed the GS fonts or exporting the path to them in your .profile file.

By the way, I use MacPorts to install all of my delegates and then install IM from source. That has worked well for me. One has to set up the IM .configure command properly to locate the delegates in /opt where MacPorts puts them.

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-26T16:24:53-07:00
by fmw42
IDL> spawn, 'which gs'
/sw/bin/gs
IDL> spawn, 'gs --version'
9.10
IDL>
try

type -a convert
and
type -a gs

and see if they are in the same location or if you have multiple versions of either.

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-26T19:30:18-07:00
by blesht
Thanks - both show only one instance in the correct locations. I had been using Macports but because I thought that might be the problem, I switched back to Fink. I guess I can try installing the delegates from Fink and ImageMagic from source as you do. I'm still puzzled as to why IM can 'find' gs from the shell, but apparently not when a process is spawned from within IDL.

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-26T20:04:10-07:00
by fmw42
blesht wrote:Thanks - both show only one instance in the correct locations. I had been using Macports but because I thought that might be the problem, I switched back to Fink. I guess I can try installing the delegates from Fink and ImageMagic from source as you do. I'm still puzzled as to why IM can 'find' gs from the shell, but apparently not when a process is spawned from within IDL.

Does you command work correctly in a simple terminal command line?

Or for that matter, what do you get from

convert -version

if you just run that in the command line in a terminal?

If gslib does not show up, then it has nothing to do with IDL. It is still an issue of IM seeing ghostscript or ghostscript is not fully installed or installed without its fonts.

Have you looked at the configure.log file in the IM folder to see what it is objecting to?

In that file about 80% or 90% towards the bottom, it will show you something like this:


Host system type: x86_64-apple-darwin10.8.0
Build system type: x86_64-apple-darwin10.8.0

Option Value
-------------------------------------------------------------------------------
Shared libraries --enable-shared=yes yes
Static libraries --enable-static=no no
Module support --with-modules=yes yes
GNU ld --with-gnu-ld=no no
Quantum depth --with-quantum-depth=16 16
High Dynamic Range Imagery
--enable-hdri=no no

Delegate Configuration:
BZLIB --with-bzlib=yes yes
Autotrace --with-autotrace=no no
Dejavu fonts --with-dejavu-font-dir=default none
DJVU --with-djvu=yes no
DPS --with-dps=yes no
FFTW --with-fftw=yes yes
FlashPIX --with-fpx=yes no
FontConfig --with-fontconfig=yes yes
FreeType --with-freetype=yes yes
GhostPCL None pcl6 (unknown)
GhostXPS None gxps (unknown)
Ghostscript None gs (9.06)
Ghostscript fonts --with-gs-font-dir=/opt/local/share/ghostscript/fonts/ /opt/local/share/ghostscript/fonts//
Ghostscript lib --with-gslib=yes yes


If that last line is

Ghostscript lib --with-gslib=yes no

or

Ghostscript lib --with-gslib=yes

The IM cannot link to gslib or gslib is not properly installed. There should be error message higher on the page that might tell you why GS is not getting installed properly.

Did FINK properly install the GS Framework? Did FINK install IM as well as your delegates? Did you tell FINK to link those delegates when it installed IM?

Can you run GS standalone to do one conversion successfully?

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-26T20:34:55-07:00
by blesht
OK - let me try to answer you questions. Some answers will be incomplete because I just completely removed both ghostscript and IM so I could start over fresh.

1. Yes, convert worked fine when invoked from the command line (bash shell).
2. convert --version resulted in:

Version: ImageMagick 6.8.8-4 Q16 x86_64 2014-02-26 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC HDRI Modules
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms ltdl lzma openexr png rsvg tiff webp wmf x xml zlib

3. I looked, but was unable to find a configure.log file. I'm not altogether sure where it would be. Fink installs the component of IM in directory /sw/bin but there was no log file that I could find.

4. To be honest, the Fink installation output scrolls by so quickly that I don't know if there were any errors. Usually, if there is an installation error, Fink stops and offers suggestions for correcting the problem. The procedure I used was the following:

fink install ghostscript
fink install imagemagick

I did nothing else, but depended on the Fink installer to do all the work. Fink notifies the user that other packages will be installed along with both ghostscript and imagemagick. I did not manually configure anything, nor did I explicitly install delegates.

5. I was able to run gs from the shell and view a file, though I did not try using it to convert a file.

I am going to re-install both ghostscript and IM and try again now. I'll try to pipe the output to a file.

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-26T20:58:08-07:00
by fmw42
Did this work from the command line in a terminal without IDL?

convert newtest.ps newtest3.png

I would be surprised if it did, since convert -version does not show gslib listed for delegates?

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-26T21:05:36-07:00
by blesht
Hi - yes, that is the real puzzle. convert newtest.ps newtest3.png works perfectly from the command line. I'm re-installing ghostscript and IM now via Macports. Thanks for sticking with me on this. Barry

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-26T21:52:28-07:00
by blesht
I re-installed ghostscript and IM via Macports. I did not see any errors on installation. gslib now seems to be present in the list of delegates both when checked from the shell (bash) and when checked from within IDL (spawn, 'convert -version').

bash-3.2$ convert -version
Version: ImageMagick 6.8.8-3 Q16 x86_64 2014-02-26 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib djvu fftw fontconfig freetype gslib jng jpeg lcms ltdl lzma png ps tiff webp x xml zlib

bash-3.2$ idl
IDL Version 8.2.3, Mac OS X (darwin x86_64 m64). (c) 2013, Exelis Visual Information Solutions, Inc.
Installation number: 230343.
Licensed for use by: Computer Sciences Corporation

IDL> spawn, 'convert -version'
Version: ImageMagick 6.8.8-3 Q16 x86_64 2014-02-26 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib djvu fftw fontconfig freetype gslib jng jpeg lcms ltdl lzma png ps tiff webp x xml zlib

However, I still have the problem from within IDL:

IDL> spawn, 'convert newtest.ps newtest4.png'
convert: bad parameters to zlib `/var/tmp/magick-60786_UD5zv5Mbaj81' @ error/png.c/MagickPNGErrorHandler/1804.
convert: corrupt image `/var/tmp/magick-60786_UD5zv5Mbaj81' @ error/png.c/ReadPNGImage/4074.
convert: Postscript delegate failed `newtest.ps': No such file or directory @ error/ps.c/ReadPSImage/837.
convert: no images defined `newtest4.png' @ error/convert.c/ConvertImageCommand/3147.

but no problems when invoked from the shell (bash):

IDL> exit
bash-3.2$ convert newtest.ps newtest3.png
bash-3.2$

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-26T22:42:06-07:00
by fmw42
I have no experience using IDL with IM. The error messages are rather confusing. It may be you need to upgrade zlib, which I believe may be needed by libpng. But it also is not handling the ps file for some reason, which is suspicious of ghostscript issues.

They typical issues when calling IM from another scripting tool are:

1) the scripting tool needs the full path to convert
2) the scripting tool needs to be configured to know about the IM delegates

I really do not know what to suggest, but I will keep thinking about it.

Can you do from IDL

convert rose: rose.gif

or

convert rose: rose.png

or

convert rose: rose.ps
convert rose.ps rose.png

rose: with the colon is a built-in image in IM. See http://www.imagemagick.org/script/forma ... tin-images


Are you sure you have the right syntax to call IM from IDL and no other configuration or arguments?

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-27T07:17:44-07:00
by blesht
Good morning. Here are the results of your suggestions (with notes following the "<-"). The IDL syntax is correct.

bash-3.2$ idl
IDL Version 8.2.3, Mac OS X (darwin x86_64 m64). (c) 2013, Exelis Visual Information Solutions, Inc.
Installation number: 230343.
Licensed for use by: Computer Sciences Corporation

IDL> spawn, 'convert rose: rose.gif' <- Created good gif image of rose, no error.
IDL> spawn, 'convert rose: rose.png' <- Created good png image of rose, no error.
IDL> spawn, 'convert rose: rose.ps' <- Created good ps file of rose, no error.
IDL> spawn, 'convert rose.ps rose.png' <- Errors as below
convert: bad parameters to zlib `/var/tmp/magick-679dI1q_YgFg1EP1' @ error/png.c/MagickPNGErrorHandler/1804.
convert: corrupt image `/var/tmp/magick-679dI1q_YgFg1EP1' @ error/png.c/ReadPNGImage/4074.
convert: Postscript delegate failed `rose.ps': No such file or directory @ error/ps.c/ReadPSImage/837.
convert: no images defined `rose.png' @ error/convert.c/ConvertImageCommand/3147.
IDL>

Clearly IDL knows the path to convert; I am not sure about your second query whether IDL knows about the delegates - would the delegates be used when rose: was converted to .gif, .png. or .ps? Is the only conversion that does not work going from ps to raster?

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-27T07:24:08-07:00
by blesht
Further information:

IDL> spawn, 'rose.gif rose.jpg' <- creates rose.jpg
IDL> spawn, 'rose.png, rose.jpg' <- Fails with error below:
IDL> spawn, 'convert rose.png rose.jpg'
convert: bad parameters to zlib `rose.png' @ error/png.c/MagickPNGErrorHandler/1804.
convert: corrupt image `rose.png' @ error/png.c/ReadPNGImage/4074.
convert: no images defined `rose.jpg' @ error/convert.c/ConvertImageCommand/3147.

Re: Errors from convert when IM invoked from IDL

Posted: 2014-02-27T09:41:46-07:00
by fmw42
try upgrading zlib delegate. I don't know if you will then have to reinstall gslib and libjpeg afterwards. I assume all those tests you ran worked fine in a terminal without IDL. Perhaps IDL makes use of different versions of those delegates?

Are you using the latest version of IDL?