[Image-SIG] Return of the transparency demon

Charlie Clark charlie at begeistert.org
Fri Aug 26 19:45:26 CEST 2005


Dear list,

because of the problems that Internet Explorer has with RGBA PNGs I'm  
trying to convert a set of images to GIFs but hitting problems as usual.

for file in files:
     file = file.split(".")
     if file[1] == "png":
         im = Image.open(".".join(file))
         new = im.convert("RGB")
         new = new.convert("P", palette=Image.ADAPTIVE, colors=256)
         mapping = [255] * 256
         mapping[0] = 0
         mask = ""
         mask = new.point(mapping, "1")
         new.paste(im, None, mask)
         new.thumbnail((32, 32), Image.ANTIALIAS)
         new.save(".".join((file[0], "gif")), "GIF")

This works for some but not all images. I know my problem is that I don't  
really understand how to convert the alpha values correctly to palette  
ones. Is the following correct - I can work out from my alpha band which  
pixels should be transparent, and set their value to 0?

Charlie


More information about the Image-SIG mailing list