1. 安装 pillow
pip install pillow -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com
2. 分解 gif 格式图片
from PIL import Image
import os
def split_image(srcfile, dstdir):
filename = srcfile.split("/")[-1]
prefix = filename[:filename.rfind(".")]
img = Image.open(srcfile)
files = list()
for i in range(img.n_frames):
img.seek(i)
new = Image.new("RGBA", img.size)
new.paste(img)
newfile = os.path.join(dstdir, "{}-{}.png".format(prefix, i))
new.save(newfile)
files.append(newfile)
return files
if "__main__" == __name__:
split_image("./abc.gif", "./bcd")
参考:https://blog.csdn.net/m0_38056893/article/details/103504790