我的Python自学之路python开发趣闻录

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

2017-05-01  本文已影响334人  我叫钱小钱

偶尔搜索图片的时候发现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)

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

positive sequence_1.gif positive sequence_2.gif reverse_1.gif reverse_2.gif
上一篇 下一篇

猜你喜欢

热点阅读