我想通过从 GIF 中提取 15 个帧来压缩 GIF 图像,这些帧最好应该是不同的。
我正在使用 Python 和 Pillow 库,但没有找到任何方法来获取 GIF 中的帧数枕头文档 https://pillow.readthedocs.io/en/latest/reference/plugins.html#module-PIL.GbrImagePlugin。我也没有找到如何从 GIF 中提取特定帧,因为枕头限制了 https://pillow.readthedocs.io/en/latest/reference/plugins.html#PIL.GifImagePlugin.GifImageFile.seek.
有没有什么方法可以提取帧而不需要遍历每个帧?
有没有更高级的GIF处理Python库?
这是 @radarhere 答案的扩展,将 .gif 分为num_key_frames
不同的部分并将每个部分保存到新图像中。
from PIL import Image
num_key_frames = 8
with Image.open('somegif.gif') as im:
for i in range(num_key_frames):
im.seek(im.n_frames // num_key_frames * i)
im.save('{}.png'.format(i))
结果是somegif.gif
分成8块另存为0
..7.png
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)