How to CREATE a transparent gif (or png) with PIL (python-imaging) How to CREATE a transparent gif (or png) with PIL (python-imaging) python python

How to CREATE a transparent gif (or png) with PIL (python-imaging)


The following script creates a transparent GIF with a red circle drawn in the middle:

from PIL import Image, ImageDrawimg = Image.new('RGBA', (100, 100), (255, 0, 0, 0))draw = ImageDraw.Draw(img)draw.ellipse((25, 25, 75, 75), fill=(255, 0, 0))img.save('test.gif', 'GIF', transparency=0)

and for PNG format:

img.save('test.png', 'PNG')