# C. Image File Formats

The Python Imaging Library supports a wide variety of raster file formats. Nearly 30 different file formats can be identified and read by the library. Write support is less extensive, but most common interchange and presentation formats are supported.

The `open` function identifies files from their contents, not their names, but the `save` method looks at the name to determine which format to use, unless the format is given explicitly.

## Format Descriptions

### BMP

PIL reads and writes Windows and OS/2 BMP files containing "1", "L", "P", or "RGB" data. 16-colour images are read as "P" images. Run-length encoding is not supported.

The `open` method sets the following `info` properties:

`compression`. Set to "bmp_rle" if the file is run-length encoded.

### CUR (read only)

CUR is used to store cursors on Windows. The CUR decoder reads the largest available cursor. Animated cursors are not supported.

### DCX (read only)

DCX is a container file format for PCX files, defined by Intel. The DCX format is commonly used in fax applications. The DCX decoder files containing "1", "L", "P", or "RGB" data. Only the first image is read.

### EPS (write-only)

The library identifies EPS files containing image data. It can also write EPS images.

### FLI, FLC (read only)

The library reads Autodesk FLI and FLC animations.

The `open` method sets the following `info` properties:

`duration`. The delay (in milliseconds) between each frame.

### FPX (read only)

The library reads Kodak FlashPix files. In the current version, only the highest resolution image is read from the file, and the viewing transform is not taken into account.

Note: To enable full FlashPix support, you need to build and install the IJG JPEG library before building the Python Imaging Library. See the distribution README for details.

### GBR (read only)

The GBR decoder reads GIMP brush files.

The `open` method sets the following `info` properties:

`description`. The brush name.

### GD (read only)

The library reads GD uncompressed files. Note that this file format cannot be automatically identified, so you must use the `open` function in the `GdImageFile` module to read such a file.

The `open` method sets the following `info` properties:

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

### GIF

The library 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 palette mode ("P") images.

The `open` method sets the following `info` properties:

`version`. Version (either "GIF87a" or "GIF89a").

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

### ICO (read only)

ICO is used to store icons on Windows. The largest available icon is read.

### IM

IM is a format used by LabEye and other applications based on the IFUNC image processing library. The library reads and writes most uncompressed interchange versions of this format.

IM is the only format that can store all internal PIL formats.

### IMT (read only)

The library reads Image Tools images containing "L" data.

### JPEG

The library reads JPEG, JFIF, and Adobe JPEG files containing "L", "RGB", or "CMYK" data. It writes standard and progressive JFIF files.

Using the `draft` method, you can speed things up by converting "RGB" images to "L", and resize images to 1/2, 1/4 or 1/8 of their original size while loading them. The draft method also configures the JPEG decoder to trade some quality for speed.

The `open` method sets the following `info` properties:

`jfif`. JFIF application marker found. If the file is not a JFIF file, this key is not present.

`adobe`. Adobe application marker found. If the file is not an Adobe JPEG file, this key is not present.

`progression`. Indicates that this is a progressive JPEG file.

The `save` method supports the following options:

`quality`. Specify the image quality, on a scale from 1 (worst) to 100 (best). The default is 75.

`optimize`. If present, indicates that the encoder should make an extra pass over the image in order to select optimal encoder settings.

`progression`. If present, indicates that this image should be stored as a progressive JPEG file.

Note: To enable JPEG support, you need to build and install the IJG JPEG library before building the Python Imaging Library. See the distribution README for details.

### MIC (read only)

The library identifies and reads Microsoft Image Composer (MIC) files. When opened, the first sprite in the file is loaded. You can use `seek` and `tell` to read other sprites from the file.

### MCIDAS (read only)

The library identifies and reads 8-bit McIdas area files.

### MPEG (identify only)

The library identifies MPEG files.

### MSP

The library identifies and reads MSP files from Windows 1 and 2. The library writes uncompressed (Windows 1) versions of this format.

### PCD (read only)

The library reads PhotoCD files containing "RGB" data. By default, the 768x512 resolution is read. You can use the `draft` method to read the lower resolution versions instead, thus effectively resizing the image to 384x256 or 192x128. Higher resolutions cannot be read by the Python Imaging Library.

### PCX

The library reads and writes PCX files containing "1", "L", "P", or "RGB" data.

### PDF (write only)

The library can write PDF (Acrobat) images. Such images are written as binary PDF 1.1 files, using either JPEG or HEX encoding depending on the image mode (and whether JPEG support is available or not).

### PNG

The library identifies, reads, and writes PNG files containing "1", "L", "P", "RGB", or "RGBA" data. Interlaced files are currently not supported.

The `open` method sets the following `info` properties:

`gamma`. Gamma, given as a floating point number.

`transparency`. Transparency colour index. This key is omitted if the image is not a transparent palette image.

The `save` method supports the following options:

`optimize`. If present, instructs the PNG writer to make the output file as small as possible. This includes extra processing in order to find optimal encoder settings.

Note: To enable PNG support, you need to build and install the ZLIB compression library before building the Python Imaging Library. See the distribution README for details.

### PPM

The library reads and writes PBM, PGM and PPM files containing "1", "L" or "RGB" data.

### PSD (read only)

The library identifies and reads PSD files written by Adobe Photoshop 2.5 and 3.0.

### SGI (read only)

The library reads uncompressed "L" and "RGB" files. This driver is highly experimental.

### SUN (read only)

The library reads uncompressed "1", "P", "L" and "RGB" files.

### TGA (read only)

The library reads 24- and 32-bit uncompressed and run-length encoded TGA files.

### TIFF

The library reads and writes TIFF files containing "1", "L", "RGB", or "CMYK" data. It reads both striped and tiled images, pixel and plane interleaved multi-band images, and either uncompressed, or Packbits, LZW, or JPEG compressed images. The current version always writes uncompressed TIFF files.

The `open` method sets the following `info` properties:

`compression`. Compression mode.

In addition, the `tag` attribute contains a dictionary of decoded TIFF fields. Values are stored as either strings or tuples. Note that only short, long and ASCII tags are correctly unpacked by this release.

### XBM

The library reads and writes X bitmap files (mode "1").

### XPM (read only)

The library reads X pixmap files (mode "P") with 256 colours or less.

The `open` method sets the following `info` properties:

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

### File Extensions

The Python Imaging Library associates file name extensions to each file format. The `open` function identifies files from their contents, not their names, but the `save` method looks at the name to determine which format to use, unless the format is given explicitly.

`BMP`. ".bmp", ".dib"

`CUR`. ".cur"

`DCX`. ".dcx"

`EPS`. ".eps", ".ps"

`FLI`. ".fli", ".flc"

`FPX`. ".fpx"

`GBR`. ".gbr"

`GD`. ".gd"

`GIF`. ".gif"

`ICO`. ".ico"

`IM`. ".im"

`JPEG`. ".jpg", ".jpe", ".jpeg"

`MIC`. ".mic"

`MSP`. ".msp"

`PCD`. ".pcd"

`PCX`. ".pcx"

`PDF`. ".pdf"

`PNG`. ".png"

`PPM`. ".pbm", ".pgm", ".ppm"

`PSD`. ".psd"

`SGI`. ".bw", ".rgb", ".cmyk"

`SUN`. ".ras"

`TGA`. ".tga"

`TIFF`. ".tif", ".tiff"

`XBM`. ".xbm"

`XPM`. ".xpm"

Keep in mind that not all of these formats can actually be saved by the library.