ImageSequence Module

The ImageSequence module contains a wrapper class that lets youiterate over the frames of an image sequence.

Extracting frames from an animation

  1. from PIL import Image, ImageSequence
  2.  
  3. im = Image.open("animation.fli")
  4.  
  5. index = 1
  6. for frame in ImageSequence.Iterator(im):
  7. frame.save("frame%d.png" % index)
  8. index = index + 1

The Iterator class

  • class PIL.ImageSequence.Iterator(im)[源代码]
  • This class implements an iterator object that can be used to loopover an image sequence.

You can use the [] operator to access elements by index. This operatorwill raise an IndexError if you try to access a nonexistentframe.

参数:im – An image object.