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]

Bases: object

isatty()[source]
read(n=0)[source]

Read data.

Parameters

n – Number of bytes to read. If omitted or zero, read until end of region.

Returns

An 8-bit string.

readline()[source]

Read a line of text.

Returns

An 8-bit string.

readlines()[source]

Read multiple lines of text.

Returns

A list of 8-bit strings.

seek(offset, mode=0)[source]

Move file pointer.

Parameters
  • offset – Offset in bytes.

  • mode – Starting position. Use 0 for beginning of region, 1 for current offset, and 2 for end of region. You cannot move the pointer outside the defined region.

tell()[source]

Get current file pointer.

Returns

Offset from start of region, in bytes.

FontFile Module

GdImageFile Module

GimpGradientFile Module

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

Bases: GradientFile

class PIL.GimpGradientFile.GradientFile[source]

Bases: object

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]

Bases: object

getpalette()[source]
rawmode = 'RGB'

ImageDraw2 Module

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.: https://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:2:0.

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

In JPEG compressed data a JPEG marker is used instead of an EXIF tag. (ref.: https://www.exiv2.org/tags.html)

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.: https://en.wikipedia.org/wiki/Quantization_matrix#Quantization_matrices, https://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.: https://web.archive.org/web/20120328125543/http://www.jpegcameras.com/libjpeg/libjpeg-3.html

PaletteFile Module

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

Bases: object

getpalette()[source]
rawmode = 'RGB'

PcfFontFile Module

PngImagePlugin.iTXt Class

PngImagePlugin.PngInfo Class

TarIO Module

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

Bases: ContainerIO

close()[source]

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 unsigned integer.

Parameters
  • 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 unsigned integer.

Parameters
  • 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]
PIL._binary.si16le(c, o=0)[source]

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

Parameters
  • c – string containing bytes to convert

  • o – offset of bytes to convert in string

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

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

Parameters
  • c – string containing bytes to convert

  • o – offset of bytes to convert in string