"""使用imageio重新生成一个GIF"""
import imageio
from PIL import Image
def preProcess(image_list):
"""处理一下图片大小"""
for image_name in image_list:
im = Image.open(image_name)
im = im.resize((100, 100)) # 都搞成(100,100)尺寸的
im.save(image_name, False) # False指的是覆盖掉之前尺寸不规范的图片
def create_gif(image_list, gif_name, duration=1):
"""制作gif图"""
frames = []
for image_name in image_list:
frames.append(imageio.imread(image_name))
imageio.mimsave(gif_name, frames, 'GIF', duration=duration) # 选择'GIF'类型
if __name__ == '__main__':
# image_list放上自己所需要合成的图片名
image_list = ['1.jpeg', '2.jpeg', '3.jpeg', '4.jpeg', '5.jpeg', '6.jpeg']
# gif_name:导出的gif图名
gif_name = 'new.gif'
duration = 1 # 这里的duration单位是1秒,与PIL.Image不一样(1ms)
preProcess(image_list) # 处理一下图片尺寸
create_gif(image_list, gif_name, duration) # 开始制作
Note that phrase im.save(image_name, False)
before because you can not overwrite the original picture, lead to the formation of large and small gif map or black bars, only added to the False before overwriting non-standard size pictures
1. Material (I have adjusted the size of the map Qi)