Page 1 of 1

-colors 256 stuffs up alpha dithering in png

Posted: 2009-06-16T04:18:33-07:00
by nurgus
Hi all,

This is the second of my two current headaches with the otherwise brilliant Imagemagick.

Trying to keep the size of my png (with alpha) thumbnails down by converting them to 256 colors, depth 8. It really does the job on file size and quality in version 6.3.7. But versions 6.4.5 and 6.5.2-9 it looks terrible.

Example:

Code: Select all

convert thumb.png -colors 256 -depth 8 thumb1.png
Original:Image Version 6.3.7:Image Versions 6.4.5+:Image

Something changed.. what can I do to get the same result as in 6.3.7?

Thanks.

Re: -colors 256 stuffs up alpha dithering in png

Posted: 2009-06-16T10:20:20-07:00
by fmw42
convert thumb.png -alpha off -colors 256 -alpha on -depth 8 thumb3.png

seems to work for me

Re: -colors 256 stuffs up alpha dithering in png

Posted: 2009-06-16T11:21:18-07:00
by nurgus
Hmm - the file size isn't as small as the original version.

6.3.7 original is 4.9kb, new version with just "-depth 8" is 9.6kb and "-alpha off -colors 256 -alpha on -depth 8" is 8.9kb. Not as good as the original but certainly good enough for me to stop wrestling with.

Many thanks for your help. 8)

Re: -colors 256 stuffs up alpha dithering in png

Posted: 2009-06-16T13:05:05-07:00
by fmw42
try adding -type PaletteMatte and see if that helps make it smaller

Re: -colors 256 stuffs up alpha dithering in png

Posted: 2009-06-16T20:15:52-07:00
by anthony
I believe it is the sub-format of PNG the IM decided to save the image as. Presumably as the number of colors is less than 256 (including semi-transparent colors) it decided to use PNG8 sub-format. which under IM only allows boolean transparency (like GIF). that is it gets it wrong.

Try adding changing the output file name to PNG32:thumb3.png to force the other sub-format.

If you want to use PNG8 then you need to forget semi-transparency, as the PNG coder current does not handle it.
OR use a dedicated PNG8 converter like pngnq
See PNG alturnatives
http://www.imagemagick.org/Usage/formats/#png_non-im

It is a bit of a shame that the IM PNG8 coder does not handle semi-transparent colors. But Glenn, the programmer involved (both in the IM coder and PNG format itself) is a very busy person.

Re: -colors 256 stuffs up alpha dithering in png

Posted: 2009-06-16T20:48:18-07:00
by fmw42
Good point about PNG8 binary transparency, Anthony! I did not even think about that.