将每帧图片缩小尺寸后,再次合成gif,代码如下:
from PIL import Image,ImageSequence
import os
gifPath = 'c:\\t.gif'
oriGif = Image.open(gifPath)
lifeTime = oriGif.info['duration']
imgList = []
imgNew = []
for i in ImageSequence.Iterator(oriGif):
print (i.copy())
imgList.append(i.copy())
for index,f in enumerate(imgList):
f.save("c:\\gif\\%d.png" % index)
img = Image.open("c:\\gif\\%d.png" % index)
img.thumbnail((200,100),Image.ANTIALIAS)
imgNew.append(img)
imgNew[0].save("c:\\new.gif",'gif',save_all=True,append_images=imgNew[1:],loop=0,
duration=lifeTime)