We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

GIF

PIL reads GIF87a and GIF89a versions of the GIF file format. The library writes run-length encoded GIF87a files. Note that GIF files are always read as grayscale (“L”) or palette mode (“P”) images.

The open method sets the following info properties:

background

Default background colour (a palette colour index).

duration

Time between frames in an animation (in milliseconds).

transparency

Transparency colour index. This key is omitted if the image is not transparent.

version

Version (either “GIF87a” or “GIF89a”).

Reading Sequences

The GIF loader supports the seek and tell methods. You can seek to the next frame (im.seek(im.tell()+1), or rewind the file by seeking to the first frame. Random access is not supported.

Reading Local Images

The GIF loader creates an image memory the same size as the GIF file’s logical screen size, and pastes the actual pixel data (the local image) into this image. If you only want the actual pixel rectangle, you can manipulate the size and tile attributes before loading the file:

im = Image.open(...)

if im.tile[0][0] == "gif":
    # only read the first "local image" from this GIF file
    tag, (x0, y0, x1, y1), offset, extra = im.tile[0]
    im.size = x1-x0, y1-y0
    im.tile = [(tag, (0, 0) + im.size, offset, extra)]