Page 1 of 1

White Background lost while upgrading imagemagick??

Posted: 2018-03-27T10:54:25-07:00
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?

Re: White Background lost while upgrading imagemagick??

Posted: 2018-03-27T12:01:13-07:00
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.

Re: White Background lost while upgrading imagemagick??

Posted: 2018-03-27T15:32:27-07:00
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".