python opencv实现gif图片分解的示例代码
时间:2021-05-05 15:38:45|栏目:Python代码|点击: 次
案例:将和当前脚本同目录下的gif图片分解成png图片,并将分解后的图片保存到pics目录下,将其从0开始命名。

GIF 动图的分解可以利用 PIL模块的Image类来实现。
from PIL import Image
import os
"""
将一张GIF动图分解到指定文件夹
src_path:要分解的gif的路径
dest_path:保存后的gif路径
"""
def gifSplit(src_path, dest_path, suffix="png"):
img = Image.open(src_path)
for i in range(img.n_frames):
img.seek(i)
new = Image.new("RGBA", img.size)
new.paste(img)
new.save(os.path.join(dest_path, "%d.%s" %(i, suffix)))
gifSplit('tiga.gif', r'./pics')
分解并保存后:

栏 目:Python代码
下一篇:python多维数组切片方法
本文标题:python opencv实现gif图片分解的示例代码
本文地址:http://www.codeinn.net/misctech/115375.html






