[Image-SIG] Convert RGB to RGBA

Fredrik Lundh fredrik at pythonware.com
Fri Aug 18 19:27:08 CEST 2006


Angelo wrote:

> Is it possible to convert a RGB image (png, tga or gif image) to RGBA
> with PIL, and how to do that ? . With im.convert(mode, matrix) ? .

the alpha layer controls transparency, and doesn't have any direct 
relation to the RGB values.  to add an alpha layer to an image, you can 
use a direct convert:

	imOut = im.convert("RGBA") # sets alpha to 255

if you have an RGB image, you can also modify it in place

	im.putalpha(value) # set alpha to given value

or

	im.putalpha(matte) # where matte is a mode "L" image

</F>



More information about the Image-SIG mailing list