您的位置:首页 > 编程语言 > Python开发

python操作gif

2020-06-09 12:28 363 查看

精选30+云产品,助力企业轻松上云!>>>

 

python读取以及保存gif图

冬日and暖阳 2018-09-21 13:56:31  5899  收藏 1
展开
1.使用模块 imageio
imageio.mimread: 读取gif,每一帧会存放到list的一个位置中
imageio.mimsave: 保存gif,输入也是一个list数组



注意::
不要用matplotlib.pylot.imread,这样读出来的数据会有问题

 

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 matplotlib pylot