The Python Imaging Library
  Copyright © 1997 by Fredrik Lundh <fredrik@pythonware.com>  
  Updated 18 Aug 1997  

< Reference | Concepts | The Image Class >

Concepts

The Python Imaging Library handles raster image data, that is, rectangles of pixel data.

Bands

An image can consist of one or more bands of data. The Python Imaging Library allows you to store several bands in a single image, provided they all have the same dimensions and depth.

To get the number of bands in an image, check the length of the mode attribute.

Mode

The mode of an image defines the type and depth of a pixel in the image, and the number of bands. The current release supports the following modes:

You can read the mode of an image through the mode attribute. This is a string containing one of the above values. Note that each character in this string corresponds to a band in the image.

Size

You can read the image size through the size attribute. This is a 2-tuple, containing the horizontal and vertical size in pixels.

Coordinate System

The Python Imaging Library uses a Cartesian pixel coordinate system, with (0,0) in the upper left corner. Note that the coordinates refer to the implied pixel corners; the centre of a pixel addressed as (0, 0) actually lies at (0.5, 0.5):

Coordinates are usually passed to the library as 2-tuples (x, y). Rectangles are represented as 4-tuples, with the upper left corner given first. For example, a rectangle covering all of an 800x600 pixel image is written as (0, 0, 800, 600).

Palette

The palette mode ("P") uses a colour palette to define the actual colour for each pixel. The palette is represented by an ImagePalette, which is used to map to any of the other modes.

Info

You can attach auxiliary information to an image using the info attribute. This is a dictionary object. How such information is handled when loading and saving image files is up to the file format handler (see the section on Image File Formats).

< Reference | Concepts | The Image Class >