Search code examples
linuximagemagickimagemagick-convert

Converting from PDF to PNG: smooth gradient gets visible edges


I am converting pages from a pdf-file to png images. However, on a specific page I had a shaded cube and the resulting png image gets noticeable 'edges' that I am unable to remove. See image below.

I am running an Amazon Lightsail linux server. Here is my imagemagick version:

Version: ImageMagick 6.7.8-9 2016-06-22 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

I have tried many different variants of the following:

convert -density 800 -quality 100 cubefile.pdf[$i] -resize 25% p0$i.png

I have tried using other options such as many different density/resize combinations, "-depth" and "-colorspace RGB", "-antialias", "-normalize", either separately or together - but I can't find anything that helps. Been at it a few hours now, but think I need some outside help.

Here is a screenshot of the image from the original pdf file where the color has a smooth transition, and the resulting png image, where I have the "lines" I talked about. There is probably a proper term for this, but I don't know what it is.

Reults

Is there an option for fixing this?

Edit
Pdf-file available here:
http://www.filedropper.com/cubefile


Solution

  • In Imagemagick 6.9.10.20 Q16 Mac OSX with Ghostscript 9.26 and libpng 1.6.35, the following command works fine for me. Note that 288=4*72, where 72 is the default dpi. So I resize by 25% to reduce the size back down to its original size.

    convert -density 288 cubefile.pdf -alpha off -resize 25% cubefile.png
    


    enter image description here

    Check your version of Ghostscript. Since your PDF has transparency, even though it is fully opaque, be sure your delegates.xml file for decode ps:alpha uses sDEVICE="pngalpha" and not "pnmraw". You can check your delegates by convert -list configure | grep "DELEGATES". You can check your version of Ghostscript bygs --version. Also check your version of libpng. You can do that byconvert -list format` and look at the line starting with PNG. The version will be at the end of the line.

    Here it is enlarged by 4 without resizing back down.

    convert -density 288 cubefile.pdf -alpha off cubefile2.png
    


    enter image description here