To get the alpha layer of an RGBA image, you just need to:
red, green, blue, alpha = img.split()
or
alpha = img.split()[-1]
And there is a way to set the alpha layer:
img.putalpha(alpha)
The transparency key is used only to determine the transparency index in palette mode (P). If you also want to close the transparency window of the palette mode and cover all cases, you could do this
if img.mode in ('RGBA', 'LA') or (img.mode == 'P' and 'transparency' in img.info): alpha = img.convert('RGBA').split()[-1]
Note. A conversion method is needed when image.mode is LA, due to an error in PIL.
Nadia Alramli Dec 26 '09 at 11:06 2009-12-26 11:06
source share