18
votes

Here is an image: Gradient1
This image is a simple black-to-transparent gradient saved in full RGBA PNG.

Here is the same image, converted to indexed-alpha PNG by GIMP (Photoshop produces the same result)
Gradient2
As you can see, the gradient is now half-opaque, half-transparent.

Here is the same image again, only this time it was converted to indexed-alpha PNG by a PHP script I wrote:
Gradient3

So my question is: Why are GIMP and Photoshop unable to support partial transparency in indexed images, when the PHP script clearly shows that such an image can be created with no problems?
Is there anything "wrong" with an image whose pallette contains alpha information?
A more programming-related question: Does this transparency in the last image work in Internet Explorer 6?

5
optipng -force correctly saves it as indexed-alpha.Mechanical snail
@Mechanicalsnail I could not reproduce on my own image with optipng 0.7.7, even at maximum optimization level. The man page, under section “Bugs”, mention that color palette reductions and bit depth reductions are only partially supported. Perhaps it only works when your color is pure black?Maëlan

5 Answers

6
votes

I've finally found the actual answer: There is a metadata entry that allows you to define the alpha value of each colour in the colour table. Most graphics programs don't make use of this, but it does exist and can be used, in particular by GD.

5
votes

Another option besides fireworks is pngquant, a command line application that will convert a rgba png into an indexed png with transparency.

I found this post which talks some more about how to use it.

IE6 and earlier in windows does not support variable transparency PNGs without annoying workarounds. An indexed PNG will only show the fully opaque parts which usually works pretty well. A drop shadow would disappear but the opaque parts of the logo or icon would continue to show.

This page has a better explanation and instructions with more png compression and quantization tools: http://calendar.perfplanet.com/2010/png-that-works/

4
votes

For the record, PNG does not literally support indexed images with an alpha channel. What is really happening is that PNG allows you to add additional colors to the color table (i.e. index) with alpha values in those colors... not a complete alpha channel. FWIW...

1
votes

Yeah I know what you mean. Fireworks is the only image editing program that I know of that can create and edit PNG8+Alpha without problems. I wish more paint programs would support this format cause Fireworks is expensive!

0
votes

I found a way in GIMP to create or convert an image with reduced color palette and alpha channel. The trick is to add a mask to the layer.

Full steps to reproduce:

  1. Have your image in one layer
  2. Add a mask to the layer. Select Transfer layer's alpha channel.
  3. Convert to Indexed (Image -> Mode -> Indexed...)
  4. Save as PNG

Now your image has reduced colors and reduced size, but it keeps your smooth transparency.