Skip to content Skip to sidebar Skip to footer

How To Create A Transparent Gif (or Png) With Pil (python-imaging)

Trying to create a transparent gif with PIL. So far I have this: from PIL import Image img = Image.new('RGBA', (100, 100), (255, 0, 0, 0)) img.save('test.gif', 'GIF',

Solution 1:

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

from PIL import Image, ImageDraw

img = 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')

Post a Comment for "How To Create A Transparent Gif (or Png) With Pil (python-imaging)"