White Background lost while upgrading imagemagick??

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
mattpslab
Posts: 1
Joined: 2018-03-27T10:44:14-07:00
Authentication code: 1152

White Background lost while upgrading imagemagick??

Post by mattpslab »

I'm trying to convert PDFs to PNGs using ImageMagick and Ghostscript.

The image on the left was created used ImageMagick 6.7.5 and Ghostscript 9.05.
The command was
$cmd = '/usr/bin/convert upload/foo.pdf -density 1200x1200 -quality 100 -resize '.$width.'x'.$height.' rename/foo.png ';

My host changed the software on server which now has ImageMagick 6.8.0-1 and Ghostscript 9.06. I ran my script again and page was now transparent instead of white. With a black webpage behind it, the music notes could not be seen.

I changed the command to try to force the background to be white, by adding alpha off as follows
$cmd = '/usr/bin/convert upload/foo.pdf -density 1200x1200 -quality 100 -alpha off -resize '.$width.'x'.$height.' rename/foo.png ';

this made the background white as desired, but the image quality is now degraded (image on the right).

What is the best way to have a white background AND same music quality as before?
Last edited by mattpslab on 2018-11-17T10:25:44-07:00, edited 1 time in total.
Thanks, Matt.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: White Background lost while upgrading imagemagick??

Post by fmw42 »

Please post your examples to some free hosting service such as dropbox.com that won't change the format and put the URLs here so we can examine your images and commands.

If the PDF is CMYK, then add -colorspace sRGB before reading the PDF. Also put the -density before reading the PDF.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: White Background lost while upgrading imagemagick??

Post by snibgo »

"-alpha off" will cause visible problems when transparency has been used for antialiasing. If your images are sRGB, not CMYK, a better method is probably "-background white -layers flatten".
snibgo's IM pages: im.snibgo.com
Post Reply