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", transparency=0)
Everything I've found so far refers to manipulating an existing image to adjust it's transparency settings or overlaying a transparent image onto another. I merely want to create a transparent GIF (to then draw onto).
putpixel((x, y), (255, 255, 255, 0)) can make a pixel transparent.
Image. open() Opens and identifies the given image file. This is a lazy operation; this function identifies the file, but the file remains open and the actual image data is not read from the file until you try to process the data (or call the load() method).
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With