python PIL.Image make a GIF

The following code, you simply pictures sorted and then a change of name, change of the code number n can be.

import PIL.Image as Image

def get_gif(n, t=1000):
	"""n张图片, t此处设置默认1秒"""
    imgs = []
    for i in range(1, n):
        pic_name = '{}.jpeg'.format(i)
        temp = Image.open(pic_name)
        temp = temp.resize((200, 200))  # 图最好一样大小,这里直接传整个(size)进去
        imgs.append(temp)
        save_name = '{}.gif'.format('one')
        imgs[0].save(save_name, save_all=True, append_images=imgs, duration=t)
        # save_all=True 保存所有图片对象,否则只存一张
        # append_images=imgs    imgs为存放对象们的列表
        # duration=t            GIF的间隔时间为t,单位是ms=0.001s
    return save_name

if __name__ == '__main__':

    save_name = get_gif(6, 500)
    print('文件是:{}'.format(save_name))

1. Materials

Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description

2. Results

Here Insert Picture Description
Here Insert Picture Description

Published 131 original articles · won praise 81 · views 60000 +

Guess you like

Origin blog.csdn.net/weixin_43469047/article/details/103442698