ImageSequence Module

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

Extracting frames from an animation

from PIL import Image, ImageSequence

with Image.open("animation.fli") as im:
    index = 1
    for frame in ImageSequence.Iterator(im):
        frame.save(f"frame{index}.png")
        index += 1

The Iterator class

class PIL.ImageSequence.Iterator(im)[source]

This class implements an iterator object that can be used to loop over an image sequence.

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

Parameters:

im – An image object.

Functions

PIL.ImageSequence.all_frames(im, func=None)[source]

Applies a given function to all frames in an image or a list of images. The frames are returned as a list of separate images.

Parameters:
  • im – An image, or a list of images.

  • func – The function to apply to all of the image frames.

Returns:

A list of images.