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)
代码有些失帧,如果有专业朋友也请告知如何避免失贞的方法。
![](https://img.haomeiwen.com/i12778909/5a0ad9ef97610d3a.gif)
![](https://img.haomeiwen.com/i12778909/37a41907c4b1ca7f.gif)
![](https://img.haomeiwen.com/i12778909/1cf024deda67f4ef.gif)
![](https://img.haomeiwen.com/i12778909/d63f59cf90ba44d6.gif)