PIL Package (autodoc of remaining modules)

Reference for modules whose documentation has not yet been ported or written can be found here.

BdfFontFile Module

ContainerIO Module

class PIL.ContainerIO.ContainerIO(file, offset, length)[source]
isatty()[source]
read(n=0)[source]
readline()[source]
readlines()[source]
seek(offset, mode=0)[source]
tell()[source]

ExifTags Module

FontFile Module

GdImageFile Module

GimpGradientFile Module

class PIL.GimpGradientFile.GimpGradientFile(fp)[source]

Bases: PIL.GimpGradientFile.GradientFile

class PIL.GimpGradientFile.GradientFile[source]
getpalette(entries=256)[source]
gradient = None
PIL.GimpGradientFile.curved(middle, pos)[source]
PIL.GimpGradientFile.linear(middle, pos)[source]
PIL.GimpGradientFile.sine(middle, pos)[source]
PIL.GimpGradientFile.sphere_decreasing(middle, pos)[source]
PIL.GimpGradientFile.sphere_increasing(middle, pos)[source]

GimpPaletteFile Module

class PIL.GimpPaletteFile.GimpPaletteFile(fp)[source]
getpalette()[source]
rawmode = 'RGB'

ImageCms Module

ImageDraw2 Module

ImageFileIO Module

The ImageFileIO module can be used to read an image from a socket, or any other stream device.

Deprecated. New code should use the PIL.ImageFile.Parser class in the PIL.ImageFile module instead.

See also

modules PIL.ImageFile.Parser

class PIL.ImageFileIO.ImageFileIO(fp)[source]

Bases: _io.BytesIO

ImageShow Module

ImageTransform Module

JpegPresets Module

JPEG quality settings equivalent to the Photoshop settings.

More presets can be added to the presets dict if needed.

Can be use when saving JPEG file.

To apply the preset, specify:

quality="preset_name"

To apply only the quantization table:

qtables="preset_name"

To apply only the subsampling setting:

subsampling="preset_name"

Example:

im.save("image_name.jpg", quality="web_high")

Subsampling

Subsampling is the practice of encoding images by implementing less resolution for chroma information than for luma information. (ref.: http://en.wikipedia.org/wiki/Chroma_subsampling)

Possible subsampling values are 0, 1 and 2 that correspond to 4:4:4, 4:2:2 and 4:1:1 (or 4:2:0?).

You can get the subsampling of a JPEG with the JpegImagePlugin.get_subsampling(im) function.

Quantization tables

They are values use by the DCT (Discrete cosine transform) to remove unnecessary information from the image (the lossy part of the compression). (ref.: http://en.wikipedia.org/wiki/Quantization_matrix#Quantization_matrices, http://en.wikipedia.org/wiki/JPEG#Quantization)

You can get the quantization tables of a JPEG with:

im.quantization

This will return a dict with a number of arrays. You can pass this dict directly as the qtables argument when saving a JPEG.

The tables format between im.quantization and quantization in presets differ in 3 ways:

  1. The base container of the preset is a list with sublists instead of dict. dict[0] -> list[0], dict[1] -> list[1], ...
  2. Each table in a preset is a list instead of an array.
  3. The zigzag order is remove in the preset (needed by libjpeg >= 6a).

You can convert the dict format to the preset format with the JpegImagePlugin.convert_dict_qtables(dict_qtables) function.

Libjpeg ref.: http://www.jpegcameras.com/libjpeg/libjpeg-3.html

OleFileIO Module

OleFileIO_PL: Module to read Microsoft OLE2 files (also called Structured Storage or Microsoft Compound Document File Format), such as Microsoft Office documents, Image Composer and FlashPix files, Outlook messages, ... This version is compatible with Python 2.6+ and 3.x

version 0.30 2014-02-04 Philippe Lagadec - http://www.decalage.info

Project website: http://www.decalage.info/python/olefileio

Improved version of the OleFileIO module from PIL library v1.1.6 See: http://www.pythonware.com/products/pil/index.htm

The Python Imaging Library (PIL) is
Copyright (c) 1997-2005 by Secret Labs AB Copyright (c) 1995-2005 by Fredrik Lundh

OleFileIO_PL changes are Copyright (c) 2005-2014 by Philippe Lagadec

See source code and LICENSE.txt for information on usage and redistribution.

WARNING: THIS IS (STILL) WORK IN PROGRESS.

class PIL.OleFileIO.OleFileIO(filename=None, raise_defects=40)[source]

OLE container object

This class encapsulates the interface to an OLE 2 structured storage file. Use the {@link listdir} and {@link openstream} methods to access the contents of this file.

Object names are given as a list of strings, one for each subentry level. The root entry should be omitted. For example, the following code extracts all image streams from a Microsoft Image Composer file:

ole = OleFileIO("fan.mic")

for entry in ole.listdir():
    if entry[1:2] == "Image":
        fin = ole.openstream(entry)
        fout = open(entry[0:1], "wb")
        while True:
            s = fin.read(8192)
            if not s:
                break
            fout.write(s)

You can use the viewer application provided with the Python Imaging Library to view the resulting files (which happens to be standard TIFF files).

close()[source]

close the OLE file, to release the file object

dumpdirectory()[source]

Dump directory (for debugging only)

dumpfat(fat, firstindex=0)[source]

Displays a part of FAT in human-readable form for debugging purpose

dumpsect(sector, firstindex=0)[source]

Displays a sector in a human-readable form, for debugging purpose.

exists(filename)[source]

Test if given filename exists as a stream or a storage in the OLE container.

filename: path of stream in storage tree. (see openstream for syntax) return: True if object exist, else False.

get_metadata()[source]

Parse standard properties streams, return an OleMetadata object containing all the available metadata. (also stored in the metadata attribute of the OleFileIO object)

new in version 0.25

get_rootentry_name()[source]

Return root entry name. Should usually be ‘Root Entry’ or ‘R’ in most implementations.

get_size(filename)[source]

Return size of a stream in the OLE container, in bytes.

filename: path of stream in storage tree (see openstream for syntax) return: size in bytes (long integer) raise: IOError if file not found, TypeError if this is not a stream.

get_type(filename)[source]

Test if given filename exists as a stream or a storage in the OLE container, and return its type.

filename: path of stream in storage tree. (see openstream for syntax) return: False if object does not exist, its entry type (>0) otherwise:

  • STGTY_STREAM: a stream
  • STGTY_STORAGE: a storage
  • STGTY_ROOT: the root entry
getctime(filename)[source]

Return creation time of a stream/storage.

filename: path of stream/storage in storage tree. (see openstream for syntax) return: None if creation time is null, a python datetime object otherwise (UTC timezone)

new in version 0.26

getmtime(filename)[source]

Return modification time of a stream/storage.

filename: path of stream/storage in storage tree. (see openstream for syntax) return: None if modification time is null, a python datetime object otherwise (UTC timezone)

new in version 0.26

getproperties(filename, convert_time=False, no_conversion=None)[source]

Return properties described in substream.

filename: path of stream in storage tree (see openstream for syntax) convert_time: bool, if True timestamps will be converted to Python datetime no_conversion: None or list of int, timestamps not to be converted

(for example total editing time is not a real timestamp)

return: a dictionary of values indexed by id (integer)

getsect(sect)[source]

Read given sector from file on disk. sect: sector index returns a string containing the sector data.

listdir(streams=True, storages=False)[source]

Return a list of streams stored in this file

streams: bool, include streams if True (True by default) - new in v0.26 storages: bool, include storages if True (False by default) - new in v0.26 (note: the root storage is never included)

loaddirectory(sect)[source]

Load the directory. sect: sector index of directory stream.

loadfat(header)[source]

Load the FAT table.

loadfat_sect(sect)[source]

Adds the indexes of the given sector to the FAT sect: string containing the first FAT sector, or array of long integers return: index of last FAT sector.

loadminifat()[source]

Load the MiniFAT table.

open(filename)[source]

Open an OLE2 file. Reads the header, FAT and directory.

filename: string-like or file-like object

openstream(filename)[source]

Open a stream as a read-only file object (BytesIO).

filename: path of stream in storage tree (except root entry), either:
  • a string using Unix path syntax, for example: ‘storage_1/storage_1.2/stream’
  • a list of storage filenames, path to the desired stream/storage. Example: [‘storage_1’, ‘storage_1.2’, ‘stream’]

return: file object (read-only) raise IOError if filename not found, or if this is not a stream.

sect2array(sect)[source]

convert a sector to an array of 32 bits unsigned integers, swapping bytes on big endian CPUs such as PowerPC (old Macs)

PIL.OleFileIO.isOleFile(filename)[source]

Test if file is an OLE container (according to its header). filename: file name or path (str, unicode) return: True if OLE, False otherwise.

PaletteFile Module

class PIL.PaletteFile.PaletteFile(fp)[source]
getpalette()[source]
rawmode = 'RGB'

PcfFontFile Module

TarIO Module

class PIL.TarIO.TarIO(tarfile, file)[source]

Bases: PIL.ContainerIO.ContainerIO

TiffTags Module

WalImageFile Module

_binary Module

PIL._binary.i16be(c, o=0)[source]
PIL._binary.i16le(c, o=0)[source]

Converts a 2-bytes (16 bits) string to an integer.

c: string containing bytes to convert o: offset of bytes to convert in string

PIL._binary.i32be(c, o=0)[source]
PIL._binary.i32le(c, o=0)[source]

Converts a 4-bytes (32 bits) string to an integer.

c: string containing bytes to convert o: offset of bytes to convert in string

PIL._binary.i8(c)[source]
PIL._binary.o16be(i)[source]
PIL._binary.o16le(i)[source]
PIL._binary.o32be(i)[source]
PIL._binary.o32le(i)[source]
PIL._binary.o8(i)[source]