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

前端 未结 1 1830
温柔的废话
温柔的废话 2021-01-01 10:24

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)         


        
1条回答
  •  轮回少年
    2021-01-01 10:31

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

    0 讨论(0)
提交回复
热议问题