[Image-SIG] PIL, PNG and RGBA

Paul Bleisch pbleisch@digitalanvil.com
Fri, 9 Feb 2001 13:51:43 -0600


I've got the following script fragment:

	ci = Image.open( cfile ).split()
	ai = Image.open( afile ).convert( "L" ).split() ## get alpha
	cai = Image.merge( "RGBA", ( ci[0], ci[1], ci[2], ai[0] ) )
	cai.save( ofile, "PNG" )
		
	#debug code
	cais = cai.split();
      cais[0].save( ofile + '.R.png', "PNG" )
      cais[1].save( ofile + '.G.png', "PNG" )
      cais[2].save( ofile + '.B.png', "PNG" )
      cais[3].save( ofile + '.A.png', "PNG" )
      ai[0].save( afile + '.png', "PNG" )

The intent is to pull the intensity out of the RGB channels
of afile and place them in cfile's A channel and output that
to ofile.  The problem is that no matter how hard I try,
the output in ofile (which should be RGBA) is always RGB.
I've looked through the code for the PngImagePlugin at
http://w1.132.telia.com/~u13208596/pil/PngImagePlugin.py
which I am using and it appears to support RGBA output.

The debug code outputs the channels of the final image
and the sourced alpha channel.  All of these PNG files look
fine (they are all greyscale obviously).  The final ofile
PNG is RGB and has no color channels.

I'm not really familar with PNG, but it appears to be
the only format that writable format that is supported
by PIL and supports RGBA, so I seem to be screwed.

Can anybody explain why this is happening?

Thanks,
Paul