- Python Pillow教程
 - 蟒蛇Pillow - 主页
 - Python Pillow - 概述
 - Python Pillow - 环境设置
 - Python Pillow - 使用图像模块
 - Python Pillow - 处理图像
 - Python Pillow - 创建缩略图
 - Python Pillow - 合并图像
 - Python Pillow - 模糊图像
 - Python Pillow - 裁剪图像
 - Python Pillow - 翻转和旋转图像
 - Python Pillow - 调整图像大小
 - Python Pillow - 创建水印
 - Python Pillow - 向图像添加滤镜
 - Python Pillow - 图像上的颜色
 - Python Pillow - ImageDraw 模块
 - Python Pillow - 图像序列
 - Python Pillow - 在图像上写入文本
 - Python Pillow - 使用 Numpy 进行机器学习
 - Python Pillow 有用资源
 - Python Pillow - 快速指南
 - Python Pillow - 有用的资源
 - Python Pillow - 讨论
 
Python Pillow - 图像序列
Python 图像库 (PIL) 包含对图像序列(动画格式)的一些基本支持。FLI/FLC、GIF 和一些实验格式是受支持的序列格式。TIFF 文件也可以包含多个帧。
打开序列文件,PIL 会自动加载序列中的第一帧。要在不同帧之间移动,可以使用查找和告诉方法。
from PIL import Image
img = Image.open('bird.jpg')
#Skip to the second frame
img.seek(1)
try:
   while 1:
      img.seek(img.tell() + 1)
      #do_something to img
except EOFError:
   #End of sequence
   pass
输出
raise EOFError EOFError
正如我们在上面看到的,当序列结束时,您将收到 EOFError 异常。
最新版本库中的大多数驱动程序仅允许您查找下一帧(如上例所示),要倒带文件,您可能必须重新打开它。
序列迭代器类
class ImageSequence:
   def __init__(self, img):
      self.img = img
   def __getitem__(self, ix):
      try:
         if ix:
            self.img.seek(ix)
         return self.img
      except EOFError:
         raise IndexError # end of sequence
for frame in ImageSequence(img):
   # ...do something to frame...