The Python Imaging Library |
![]() |
|
Copyright © 1997 by Fredrik Lundh <fredrik@pythonware.com> | ||
Updated 18 Aug 1997 |
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.
In the following table, "open" means that a format can be identified by the library, "draft" that the draft method can be used to control loading, "load" that it can be loaded into memory, and "save" that it can be written from memory. "Experimental" means that the driver has only been tested with a few samples.
Format Operations BMP, DIB open, load, save ("1", "L", "P", "RGB"). CUR open, load ("P"). DCX open, load ("1", "L", "P", "RGB"). EPS open, save ("L", "RGB", "CMYK"). FLI, FLC open, load ("P"; experimental). FPX open, load ("L", "RGB"). GBR open, load ("L"). GD open, load ("P"). GIF open, load, save ("L", "P"; saves uncompressed only). ICO open, load ("P"). IM open, load, save. IMT open, load ("L" only). JFIF, JPEG open, draft, load, save ("L", "RGB", "CMYK"). Requires the IJG JPEG library. MCIDAS open, load ("L" only). MIC open, load ("RGBA"). MSP open, load, save ("1"; saves uncompressed only). PBM open, load, save ("1"). PGM open, load, save ("L"). PPM open, load, save ("RGB"). PCD open, draft, load ("RGB", max 768x512). PCX open, load ("1", "L", "P", "RGB"). save ("1", "L", "P", "RGB", "CMYK"). PNG open, load, save ("1", "L", "P", "RGB", "RGBA"; non-interlaced only). Requires the ZLIB library. PSD open ("1", "L", "P", "RGB"). SGI open, load ("L", "RGB"; uncompressed only). SUN open, load ("1", "L", "P", "RGB"; uncompressed only). TGA open, load ("P", "RGB"; uncompressed only). TIFF open, load, save ("1", "L", "P", "RGB", "CMYK"; loads pixel or plane interleaved; striped and tiled; uncompressed, LZW, PackBits or JPEG; saves uncompressed only). XBM open, load, save ("1"). XPM open, load ("P"). WMF open, load ("P"; limited rendering support, experimental).
The library reads 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.
Info key Value compression Set to "bmp_rle" if file is run-length encoded.
CUR is used to store cursors on Windows. The largest available cursor is read. Animated cursors are not supported.
DCX is a container file format for PCX files, defined by Intel. The DCX format is commonly used in fax applications. The library reads DCX files containing "1", "L", "P", or "RGB" data. Only the first image is read.
The library identifies EPS files containing image data. It can also write EPS images.
The library reads Autodesk FLI and FLC animations.
Info key Value duration The delay (in milliseconds) between each frame.
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.
The library reads GIMP brush files.
Info key Value description The brush name.
GD
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.
Info key Value transparency Transparency colour index. This key is omitted if the image is not transparent.
The library reads GIF87a and GIF89a versions of the GIF file format. The library writes uncompressed GIF87a files. Note that GIF files are always read as palette mode ("P") images.
Info key Value version Version (either "GIF87a" or "GIF89a"). transparency Transparency colour index. This key is omitted if the image is not transparent.
ICO is used to store icons on Windows. The largest available icon is read.
IM is a format used by LabEye and other applications based on the IFUNC image processing library. The library reads most uncompressed interchange versions of this format, but only saves "L" images.
The library reads Image Tools images containing "L" data.
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 ½, ¼ or 1/8 of their original size while loading them. The draft method also configures the JPEG decoder to trade some quality for speed.
Info key Value 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 following options can be used with the save method:
Save option Description 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.
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.
The library identifies and reads 8-bit McIdas area files.
The library identifies MPEG files.
The library identifies and reads MSP files from Windows 1 and 2. The library writes uncompressed (Windows 1) versions of this format.
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.
The library reads PCX files containing "1", "L", "P", or "RGB" data.
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).
The library identifies, reads, and writes PNG files containing "1", "L", "P", "RGB", or "RGBA" data. Interlaced files are currently not supported.
Info key Value 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 following options can be used with the save method:
Save option Description 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.
The library reads and writes PBM, PGM and PPM files containing "1", "L" or "RGB" data.
The library identifies PSD files written by Adobe Photoshop 2.5 and 3.0.
The library reads uncompressed "L" and "RGB" files. This driver is highly experimental.
The library reads uncompressed "1", "P", "L" and "RGB" files.
The library reads 24- and 32-bit uncompressed TGA files as
"RGB". This driver is highly experimental.
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.
Info key Value compression Compression mode.
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.
The library reads and writes X bitmap files (mode "1").
The library reads X pixmap files (mode "P") with 256 colours or less.
Info key Value transparency Transparency colour index. This key is omitted if the image is not transparent.
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 format looks at the name to determine which format to use, unless the format is given explicitly.
Format Extensions 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" PNG ".png" PPM ".pbm", ".pgm", ".ppm" PSD ".psd" SGI ".bw", ".rgb", ".cmyk" SUN ".ras" TGA ".tga" TIFF ".tif", ".tiff" XBM ".xbm" XPM ".xpm"
Note that only some of these formats can actually be saved by the library.