Reduce PNG color depth for use in icons

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
Rapisho
Posts: 5
Joined: 2011-10-07T22:17:53-07:00
Authentication code: 8675308

Reduce PNG color depth for use in icons

Post by Rapisho »

I need to reduce the color depth of some PNGs from 32bit to 8bit/256 colors and 4bit/16colors.
I've allready searched in the usage pages, but since my english skills are not the best and I use IM for the first time I only found these three usefull commands:

1.

Code: Select all

convert -colors 256 -depth 8 +dither  image32.png image8.png
2.

Code: Select all

convert -colors 256 -depth 8  +dither -define png:color-type=3  image32.png image8.png
3.

Code: Select all

convert -colors 256 -depth 8  +dither -define png:color-type=3 -alpha Background  image32.png image8.png
Here are the PNGs

1. Image (the preview is not shown correctly, you have to klick on it to see the transparency)
2. Image
3. Image
original 32bit Image (also not shown correctly, just follow the link)

If I load the 1. Image in my icon creation tool, Axialis IconWorkshop, it looks exactly as the 2. , everything transparent gets black.
I think what I need is something like the second image only with transparent background or transparent background with dither like in this image http://www.imagemagick.org/Usage/quanti ... ome_fs.gif if its possible for PNG.

Would be very thankful for getting some help.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Reduce PNG color depth for use in icons

Post by Bonzo »

Your first comand worked for me and changed to a 8 bit png from a 32bit.

I changed the comand around as well as the input image should be read in first.

Code: Select all

convert 1.png -colors 256 -depth 8 +dither image8.png
What version are you using?

Note: Not impressed with your image hosting site.
Rapisho
Posts: 5
Joined: 2011-10-07T22:17:53-07:00
Authentication code: 8675308

Re: Reduce PNG color depth for use in icons

Post by Rapisho »

I use the most recent version for windows on win 7.
The commend worked for me too, Irfanview shows the transparency and bit depth correctly. So I think IconWorkshop causes the problem, but I hoped theres a special option to use during conversion.

€: I have antoher idea. Which picture format support transparency with 8bit except png and gif? Gif doesn't work too.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Reduce PNG color depth for use in icons

Post by glennrp »

If you can accept binary transparency, try

Code: Select all

convert -colors 256 -depth 8 +dither  image32.png png8:image8.png
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Reduce PNG color depth for use in icons

Post by glennrp »

If you can accept binary transparency, try

Code: Select all

convert -colors 256  +dither  image32.png png8:image8.png
convert -colors 16 +dither image8.png image4.png
Rapisho
Posts: 5
Joined: 2011-10-07T22:17:53-07:00
Authentication code: 8675308

Re: Reduce PNG color depth for use in icons

Post by Rapisho »

Thank you so much! I've allready capitulated.
The png8: worked fine, the 4bit PNGs still use their transparency. I think IconWorkshop accepts only binary transparency.
Is possible to apply this to the 4 bit conversion? Or is this allready done with " -colors 16" ? In fact its not that important as it is for 8bit, but it still would be nice.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Reduce PNG color depth for use in icons

Post by glennrp »

Rapisho wrote:Thank you so much! I've allready capitulated.
The png8: worked fine, the 4bit PNGs still use their transparency. I think IconWorkshop accepts only binary transparency.
Is possible to apply this to the 4 bit conversion? Or is this allready done with " -colors 16" ? In fact its not that important as it is for 8bit, but it still would be nice.
That's why I did the 4-bit in two steps: first png8 then convert that to 16 colors (4-bit). The conversion to png8, among other things, reduces the transparency to binary. You could do that by other means such as ordered-dither of the alpha channel (the png8 conversion just does a simple 50% threshold on the alpha channel). BTW, my image4.png looks transparent to me.
Rapisho
Posts: 5
Joined: 2011-10-07T22:17:53-07:00
Authentication code: 8675308

Re: Reduce PNG color depth for use in icons

Post by Rapisho »

Sorry I didn't recognize the different file names and thought you did kind of a double post, but it still doesn't work with those both.

How do I change the threshold manually? Theres a black border at the bottom of the image. (its the 8bit version)
Image
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Reduce PNG color depth for use in icons

Post by glennrp »

Rapisho wrote:How do I change the threshold manually?

Code: Select all

convert -channel A -threshold 10% ...
Rapisho
Posts: 5
Joined: 2011-10-07T22:17:53-07:00
Authentication code: 8675308

Re: Reduce PNG color depth for use in icons

Post by Rapisho »

Thx, worked.

Only one last thing. Some of the icons have more parts with transparency than the shadow, like this:
Image

If I convert it with

Code: Select all

convert -colors 256 -depth 8 +dither -channel A -threshold 46%%  image32.png  png8:image8.png
this is the result:
Image

I guess its because that what appears grey is black with alpha. Can I still get it grey after conversion without affecting the shadow?
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Reduce PNG color depth for use in icons

Post by glennrp »

You could ordered-dither the alpha channel instead of thresholding it, but
I think just letting the dark grey become black is cleaner.

Code: Select all

convert -colors 256 -depth 8 +dither -channel A -ordered-dither 2x2  image32.png image8.png
Otherwise you could transform the particular 60%-alpha black pixels to grey-opaque ones manually
before doing the reduction, but that would be a particular operation for this specific image, not a general
solution.
Post Reply