PIL Package (autodoc of remaining modules)#

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

PIL Module#

exception PIL.UnidentifiedImageError[source]#

Bases: OSError

Raised in PIL.Image.open() if an image cannot be opened and identified.

If a PNG image raises this error, setting ImageFile.LOAD_TRUNCATED_IMAGES to true may allow the image to be opened after all. The setting will ignore missing data and checksum failures.

BdfFontFile Module#

Parse X Bitmap Distribution Format (BDF)

class PIL.BdfFontFile.BdfFontFile(fp: BinaryIO)[source]#

Bases: FontFile

Font file plugin for the X11 BDF format.

PIL.BdfFontFile.bdf_char(f: BinaryIO) tuple[str, int, tuple[tuple[int, int], tuple[int, int, int, int], tuple[int, int, int, int]], Image] | None[source]#

ContainerIO Module#

class PIL.ContainerIO.ContainerIO(file: IO, offset: int, length: int)[source]#

Bases: Generic

A file object that provides read access to a part of an existing file (for example a TAR file).

isatty() bool[source]#
read(n: int = 0) AnyStr[source]#

Read data.


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


An 8-bit string.

readline() AnyStr[source]#

Read a line of text.


An 8-bit string.

readlines() list[AnyStr][source]#

Read multiple lines of text.


A list of 8-bit strings.

seek(offset: int, mode: Literal[0, 1, 2] = 0) None[source]#

Move file pointer.

  • 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() int[source]#

Get current file pointer.


Offset from start of region, in bytes.

FontFile Module#

class PIL.FontFile.FontFile[source]#

Bases: object

Base class for raster font file handlers.

bitmap: Image | None = None#
compile() None[source]#

Create metrics and bitmap

save(filename: str) None[source]#

Save font

PIL.FontFile.puti16(fp: BinaryIO, values: tuple[int, int, int, int, int, int, int, int, int, int]) None[source]#

Write network order (big-endian) 16-bit sequence

GdImageFile Module#


This format cannot be automatically recognized, so the class is not registered for use with PIL.Image.open(). To open a gd file, use the PIL.GdImageFile.open() function instead.


THE GD FORMAT IS NOT DESIGNED FOR DATA INTERCHANGE. This implementation is provided for convenience and demonstrational purposes only.

class PIL.GdImageFile.GdImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

Image plugin for the GD uncompressed format. Note that this format is not supported by the standard PIL.Image.open() function. To use this plugin, you have to import the PIL.GdImageFile module and use the PIL.GdImageFile.open() function.

format: str | None = 'GD'#
format_description: str | None = 'GD uncompressed images'#
PIL.GdImageFile.open(fp: StrOrBytesPath | IO[bytes], mode: str = 'r') GdImageFile[source]#

Load texture from a GD image file.

  • fp – GD file name, or an opened file handle.

  • mode – Optional mode. In this version, if the mode argument is given, it must be “r”.


An image instance.


OSError – If the image could not be read.

GimpGradientFile Module#

Stuff to translate curve segments to palette values (derived from the corresponding code in GIMP, written by Federico Mena Quintero. See the GIMP distribution for more information.)

PIL.GimpGradientFile.EPSILON = 1e-10#
class PIL.GimpGradientFile.GimpGradientFile(fp)[source]#

Bases: GradientFile

File handler for GIMP’s gradient format.

class PIL.GimpGradientFile.GradientFile[source]#

Bases: object

gradient = None#
PIL.GimpGradientFile.SEGMENTS = [<function linear>, <function curved>, <function sine>, <function sphere_increasing>, <function sphere_decreasing>]#
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

File handler for GIMP’s palette format.

rawmode = 'RGB'#

ImageDraw2 Module#

(Experimental) WCK-style drawing interface operations

See also


class PIL.ImageDraw2.Pen(color, width=1, opacity=255)[source]#

Bases: object

Stores an outline color and width.

class PIL.ImageDraw2.Brush(color, opacity=255)[source]#

Bases: object

Stores a fill color

class PIL.ImageDraw2.Font(color, file, size=12)[source]#

Bases: object

Stores a TrueType font and color

class PIL.ImageDraw2.Draw(image, size=None, color=None)[source]#

Bases: object

(Experimental) WCK-style drawing interface

render(op, xy, pen, brush=None)[source]#

Sets a transformation offset.

arc(xy, start, end, *options)[source]#

Draws an arc (a portion of a circle outline) between the start and end angles, inside the given bounding box.

chord(xy, start, end, *options)[source]#

Same as arc(), but connects the end points with a straight line.

ellipse(xy, *options)[source]#

Draws an ellipse inside the given bounding box.

line(xy, *options)[source]#

Draws a line between the coordinates in the xy list.

pieslice(xy, start, end, *options)[source]#

Same as arc, but also draws straight lines between the end points and the center of the bounding box.

polygon(xy, *options)[source]#

Draws a polygon.

The polygon outline consists of straight lines between the given coordinates, plus a straight line between the last and the first coordinate.

rectangle(xy, *options)[source]#

Draws a rectangle.

text(xy, text, font)[source]#

Draws the string at the given position.

textbbox(xy, text, font)[source]#

Returns bounding box (in pixels) of given text.


(left, top, right, bottom) bounding box

textlength(text, font)[source]#

Returns length (in pixels) of given text. This is the amount by which following text should be offset.

ImageMode Module#

class PIL.ImageMode.ModeDescriptor(mode: str, bands: tuple[str, ...], basemode: str, basetype: str, typestr: str)[source]#

Bases: object

Wrapper for mode strings.

PIL.ImageMode.getmode(mode: str) ModeDescriptor[source]#

Gets a mode descriptor for the given mode.

PaletteFile Module#

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

Bases: object

File handler for Teragon-style palette files.

rawmode = 'RGB'#

PcfFontFile Module#

class PIL.PcfFontFile.PcfFontFile(fp: BinaryIO, charset_encoding: str = 'iso8859-1')[source]#

Bases: FontFile

Font file plugin for the X11 PCF format.

name = 'name'#
PIL.PcfFontFile.sz(s: bytes, o: int) bytes[source]#

PngImagePlugin.iTXt Class#

class PIL.PngImagePlugin.iTXt(text, lang=None, tkey=None)[source]#

Bases: str

Subclass of string to allow iTXt chunks to look like strings while keeping their extra information

__new__(cls, text, lang, tkey)[source]#
  • value – value for this key

  • lang – language code

  • tkey – UTF-8 version of the key name

PngImagePlugin.PngInfo Class#

class PIL.PngImagePlugin.PngInfo[source]#

Bases: object

PNG chunk container (for use with save(pnginfo=))

add(cid, data, after_idat=False)[source]#

Appends an arbitrary chunk. Use with caution.

  • cid – a byte string, 4 bytes long.

  • data – a byte string of the encoded data

  • after_idat – for use with private chunks. Whether the chunk should be written after IDAT

add_itxt(key, value, lang='', tkey='', zip=False)[source]#

Appends an iTXt chunk.

  • key – latin-1 encodable text key name

  • value – value for this key

  • lang – language code

  • tkey – UTF-8 version of the key name

  • zip – compression flag

add_text(key, value, zip=False)[source]#

Appends a text chunk.

  • key – latin-1 encodable text key name

  • value – value for this key, text or an PIL.PngImagePlugin.iTXt instance

  • zip – compression flag

TarIO Module#

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

Bases: ContainerIO[bytes]

A file object that provides read access to a given member of a TAR file.

close() None[source]#

WalImageFile Module#

This reader is based on the specification available from: https://www.flipcode.com/archives/Quake_2_BSP_File_Format.shtml and has been tested with a few sample files found using google.


This format cannot be automatically recognized, so the reader is not registered for use with PIL.Image.open(). To open a WAL file, use the PIL.WalImageFile.open() function instead.

class PIL.WalImageFile.WalImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'WAL'#
format_description: str | None = 'Quake2 Texture'#

Load image data based on tile list


Load texture from a Quake2 WAL texture file.

By default, a Quake2 standard palette is attached to the texture. To override the palette, use the PIL.Image.Image.putpalette() method.


filename – WAL file name, or an opened file handle.


An image instance.