写了个gif的压缩工具,这是脚本:
import imageio
from PIL import Image, ImageSequence
# 设置压缩比例,控制图片大小
k = 2.2
# 设置跳帧步长(多少帧取一张)
step = 1
# 设置最大动图张数
max_length = 5
img_list = []
# 读取原图
img = Image.open("fe402c79b3f3492ea27e94dd222bdf54.gif")
x = 0
for i in ImageSequence.Iterator(img):
if x%step==0:
i = i.convert('RGB')
i = i.resize((int(i.size[0]/k), int(i.size[1]/k)))
img_list.append(i)
x+=1
if x==max_length:
break
durt = (img.info)['duration'] / 1000
# 保存新图,设置循环播放(很重要)
imageio.mimsave('param-out.gif', img_list, duration=durt, loop=0)