Alpha transparency in indexed-png images
Asked Answered
O

5

18

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?

Oligarchy answered 15/11, 2010 at 11:55 Comment(2)
optipng -force correctly saves it as indexed-alpha.Wivinah
@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?Hardej
O
6

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.

Oligarchy answered 30/12, 2012 at 19:43 Comment(4)
Did you do it by hand or with a plugin, because I can't imagine doing this for existing images by hand.Narcis
I use GD for all my programmable image needs ;)Oligarchy
GD? Do I need to be reminded or just informed? (Not graphical design, or?)Narcis
To be precise: it's an ancillary chunk, which may be ignored by a decoder: W3 PNG SpecMerits
G
5

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/

Grahamgrahame answered 6/9, 2011 at 2:53 Comment(0)
D
5

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...

Dissection answered 20/7, 2012 at 22:32 Comment(1)
libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.tRNS paragraph 3. The tRNS chunk represents the alpha channel of each entry in the PLTE so that you can have index color, but still have 8-bit transparency.Forging
B
1

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!

Bun answered 23/1, 2011 at 11:16 Comment(2)
ImageAlpha does this for free and IMHO better than Fireworks.Laryngoscope
There is also Color quantizer (Windows) and Pngnq (Windows and Mac). The developer of the latter wants to make a GIMP plugin, but GIMP doesn't offer the palette, he says. Maybe someone with more time than me can convince him or use this or something? Heh..Narcis
A
0

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.

Ashia answered 30/1, 2020 at 20:26 Comment(1)
Tested with Gimp 2.10.20 on Linux: steps 1 to 3 indeed produce a Gimp image (*.xcf file) with indexed colors and an alpha channel, but step 4 exports to an indexed PNG with an all-or-nothing transparency.Hardej

© 2022 - 2024 — McMap. All rights reserved.