Python新世界生活不易 我用pythonpython热爱者

Python实现GIF动画转置 超好玩!

2018-08-10  本文已影响13人  轻松学Python111

偶尔搜索图片的时候发现Python GIF转置就随便找了两张玩玩

from PIL import Image, ImageSequence

with Image.open('pic.gif') as im:
    if im.is_animated:
        frames = [f.copy() for f in ImageSequence.Iterator(im)]
        frames.reverse() # 内置列表倒序方法
        # 将倒序后的所有帧图像保存下来
        frames[0].save('pic_reverse.gif', save_all=True, append_images=frames[1:])

# 鬼畜打乱GIF动画效果
# import random
# random.shuffle(frames)

代码有些失帧,如果有专业朋友也请告知如何避免失贞的方法。

4.gif 3.gif 2.gif 1.gif
上一篇 下一篇

猜你喜欢

热点阅读