convert on Mac OS X server produces poor image

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
MenloDIT

convert on Mac OS X server produces poor image

Post by MenloDIT »

Hi,

I have a php program that takes latex code on the fly and produces gif images of math equations. The three commands that get executed in the php code are:

Code: Select all

/usr/texbin/latex --interaction=nonstopmode myfile.tex
/usr/texbin/dvips -E myfile.dvi -o myfile.ps
/usr/local/bin/convert -density 120 -crop 0x0 -transparent "#FFFFFF" myfile.ps myfile.gif
On my linux servers, this has been working for years: the gif files are good-enough quality. Here is an example: Image.

I now need to put my program on a Mac Server. I installed the packages ImageMagick and MacTex. Unfortunately, the gif files are poorer quality and look more pixelated. Example: Image

I took the ps file from the Mac Server and ran the same convert command on my linux server; the resulting gif file looks just fine. I also tried compiling sample Tex code inside the TeXShop GUI on the Mac, and the resulting PDF looks perfectly good. All this made me conclude that the problem occurs during the convert execution.

I tried adding -antialias, but that didn't help. (I had never used it on the linux servers, anyway.) My code is based on the library LatexRender: http://www.mayer.dial.pipex.com/tex.htm

My hope is to be able to execute "convert" with the proper options, so that the result are excellent quality gif's of math equations. Can anyone suggest a pointer or two? I would really appreciate your help.

Thank you,
Gabe.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert on Mac OS X server produces poor image

Post by fmw42 »

this might be relevant

see viewtopic.php?f=1&t=14817&hilit=Mac+font

where
Magick wrote:ImageMagick utilizes Freetype to render text. Its possible that you have two different versions of Freetype or perhaps the patented Apple hinter is turned on on your Mac for improved results whereas it is not on Ubuntu.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: convert on Mac OS X server produces poor image

Post by magick »

Does your ImageMagick distribution include support for Freetype? That is a necessary delegate library for reasonable looking font renderings. Type
  • identify -list format
    identify -list configure
What you are looking for is:
  • TTF* TTF r-- TrueType font (Freetype 2.2.1)
    LIBS -lMagickCore -ltiff -lfreetype...
MenloDIT

Re: convert on Mac OS X server produces poor image

Post by MenloDIT »

magick wrote:Does your ImageMagick distribution include support for Freetype? That is a necessary delegate library for reasonable looking font renderings. Type
  • identify -list format
    identify -list configure
What you are looking for is:
  • TTF* TTF r-- TrueType font (Freetype 2.2.1)
    LIBS -lMagickCore -ltiff -lfreetype...
Yes, I believe it does, based on your instructions.

I see the following, among many other lines of info:
  • TTF* TTF r-- TrueType font (Freetype 2.3.5)
    LIBS -lMagickCore -llcms -ltiff -lfreetype...
I have started looking around, and the configuration files for FreeType and TrueType seem to be quite massive. I'm happy to try changing something if you or anyone else has a suggestion.

Many thanks in advance.

Gabe.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: convert on Mac OS X server produces poor image

Post by magick »

Try this:
  • /usr/local/bin/convert -density 480 -crop 0x0 -transparent "#FFFFFF" myfile.ps -resize 25% myfile.gif
MenloDIT

Re: convert on Mac OS X server produces poor image

Post by MenloDIT »

magick wrote:Try this:
  • /usr/local/bin/convert -density 480 -crop 0x0 -transparent "#FFFFFF" myfile.ps -resize 25% myfile.gif
Thank you for the suggestion. Unfortunately, it doesn't seem to have worked. I did confirm that -density 480 produced a larger image, but then resizing it 25% smaller still leaves a poor image.

Image

It's weird that the tops of the numbers and the thin parts of the characters are getting cut off somehow.

Thank you for any other help.
Gabe.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: convert on Mac OS X server produces poor image

Post by magick »

Do you have a modern version of Ghostscript on your system? The latest is 8.70. Do you have all the available Ghostscript fonts installed?
MenloDIT

Re: convert on Mac OS X server produces poor image

Post by MenloDIT »

magick wrote:Do you have a modern version of Ghostscript on your system? The latest is 8.70. Do you have all the available Ghostscript fonts installed?
I am running version 8.63 on the Mac.

However, on my linux box, I run version 6.50, and the quality is perfect.

For what it's worth, here is the latex code that begins the process of creating the image:

Code: Select all

\documentclass[10pt]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\pagestyle{empty}
\begin{document}
$\mbox{\fontsize{12}{16}\selectfont $3x=42022$}$
\end{document}
I should also note that in my prior posts, I had placed the latex command \boldmath into the math equation code. I did that to compensate for the extremely poor quality of the image on the Mac.

Here is an example of an equation without \boldmath. It looks like this on the Mac: Image...

...but this on the linux machine: Image

In other words, the poor quality is much more obvious when bold is turned off.

Thank you for your suggestions.
Gabe.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: convert on Mac OS X server produces poor image

Post by magick »

Edit delegates.xml and change pngalpha to pnmraw. The problem appears to the pngalpha device in Ghostscript. ImageMagick uses the pngalpha device if it detects a transparent image. Post a bug report to the Ghostscript bug forum.
MenloDIT

Re: convert on Mac OS X server produces poor image

Post by MenloDIT »

magick wrote:Edit delegates.xml and change pngalpha to pnmraw. The problem appears to the pngalpha device in Ghostscript. ImageMagick uses the pngalpha device if it detects a transparent image. Post a bug report to the Ghostscript bug forum.
Unfortunately, I didn't see any improvement with that change.

To confirm, I made the following change, which is approximately line 93 in delegates.xml:

OLD:

Code: Select all

<delegate decode="ps:alpha" stealth="True" command=""gs" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s""/>
NEW:

Code: Select all

<delegate decode="ps:alpha" stealth="True" command=""gs" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s""/>
Thank you,
Gabe.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: convert on Mac OS X server produces poor image

Post by magick »

Add -verbose to your command line and verify that the pnmraw device is being used for font rendering. We can consistently produce good results with your image when the device is pnmraw.
MenloDIT

Re: convert on Mac OS X server produces poor image

Post by MenloDIT »

magick wrote:Add -verbose to your command line and verify that the pnmraw device is being used for font rendering. We can consistently produce good results with your image when the device is pnmraw.
So, I think I just stumbled upon success. I had kept two options we discussed earlier in the convert command: the density setting to 480 along with the resize 25% option. When I removed these, but changed pngalpha to pnmraw in the delegates.xml file, I achieved satisfactory gifs. Here is a regular font example: Image, and here is a bold font example: Image.

Unless you can think of any reason this won't work for all mathematical formulae going forward, I think success has been accomplished. Thank you very much.

You mentioned that I should post a bug to the ghostscript forum. Can you provide the link to that forum?

Thanks,
Gabe
Post Reply