简体   繁体   中英

Unable to make GIF with Pillow

Please see this code which I have provided to identify the mistake I have done in the code to make a GIF in pillow

from PIL import Image, ImageDraw

def make_Image(w,h,p_1,p_2):
    
    img = Image.new('RGB', (w,h), (255,255,255))

    draw = ImageDraw.Draw(img)

    draw.rectangle([(p_1,p_2), (p_1+10,p_2+10)], fill = 'red', outline = 'blue')

    return img 

frames = []

x,y = 0,0

for i in range(10):

    new_image = make_Image(200,200,x,y)

    x = x + 20

    y = y + 20

    frames.append(new_image)

frames[0].save('gif_1.gif', format = 'GIF', append_all = frames[1:], save_all = True, duration = 1, loop = 0)

Just use append_images instead of append_all :

frames[0].save('gif_1.gif', format='GIF', append_images=frames[1:], ...

(see: https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#saving )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM