PIL Package (autodoc of remaining modules)

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

BdfFontFile Module

class PIL.BdfFontFile.BdfFontFile(fp)

Bases: PIL.FontFile.FontFile

PIL.BdfFontFile.bdf_char(f)

ContainerIO Module

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

FontFile Module

class PIL.FontFile.FontFile
bitmap = None
compile()

Create metrics and bitmap

save(filename)

Save font

PIL.FontFile.puti16(fp, values)

GdImageFile Module

class PIL.GdImageFile.GdImageFile(fp=None, filename=None)

Bases: PIL.ImageFile.ImageFile

format = 'GD'
format_description = 'GD uncompressed images'
PIL.GdImageFile.open(fp, mode='r')

GimpGradientFile Module

class PIL.GimpGradientFile.GimpGradientFile(fp)

Bases: PIL.GimpGradientFile.GradientFile

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

GimpPaletteFile Module

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

ImageDraw2 Module

class PIL.ImageDraw2.Brush(color, opacity=255)
class PIL.ImageDraw2.Draw(image, size=None, color=None)
arc(xy, start, end, *options)
chord(xy, start, end, *options)
ellipse(xy, *options)
flush()
line(xy, *options)
pieslice(xy, start, end, *options)
polygon(xy, *options)
rectangle(xy, *options)
render(op, xy, pen, brush=None)
settransform(offset)
symbol(xy, symbol, *options)
text(xy, text, font)
textsize(text, font)
class PIL.ImageDraw2.Font(color, file, size=12)
class PIL.ImageDraw2.Pen(color, width=1, opacity=255)

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)

Bases: _io.BytesIO

ImageShow Module

class PIL.ImageShow.DisplayViewer

Bases: PIL.ImageShow.UnixViewer

get_command_ex(file, **options)
class PIL.ImageShow.UnixViewer

Bases: PIL.ImageShow.Viewer

show_file(file, **options)
class PIL.ImageShow.Viewer
format = None
get_command(file, **options)
get_format(image)
save_image(image)
show(image, **options)
show_file(file, **options)
show_image(image, **options)
class PIL.ImageShow.XVViewer

Bases: PIL.ImageShow.UnixViewer

get_command_ex(file, title=None, **options)
PIL.ImageShow.register(viewer, order=1)
PIL.ImageShow.show(image, title=None, **options)
PIL.ImageShow.which(executable)

ImageTransform Module

class PIL.ImageTransform.AffineTransform(data)

Bases: PIL.ImageTransform.Transform

method = 0
class PIL.ImageTransform.ExtentTransform(data)

Bases: PIL.ImageTransform.Transform

method = 1
class PIL.ImageTransform.MeshTransform(data)

Bases: PIL.ImageTransform.Transform

method = 4
class PIL.ImageTransform.QuadTransform(data)

Bases: PIL.ImageTransform.Transform

method = 3
class PIL.ImageTransform.Transform(data)

Bases: PIL.Image.ImageTransformHandler

getdata()
transform(size, image, **options)

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

PaletteFile Module

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

PcfFontFile Module

class PIL.PcfFontFile.PcfFontFile(fp)

Bases: PIL.FontFile.FontFile

name = 'name'
PIL.PcfFontFile.sz(s, o)

PngImagePlugin.iTXt Class

class PIL.PngImagePlugin.iTXt

Bases: str

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

__new__(cls, text, lang, tkey)
Parameters:
  • value – value for this key
  • lang – language code
  • tkey – UTF-8 version of the key name

PngImagePlugin.PngInfo Class

class PIL.PngImagePlugin.PngInfo

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

add(cid, data)

Appends an arbitrary chunk. Use with caution.

Parameters:
  • cid – a byte string, 4 bytes long.
  • data – a byte string of the encoded data
add_itxt(key, value, lang='', tkey='', zip=False)

Appends an iTXt chunk.

Parameters:
  • 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=0)

Appends a text chunk.

Parameters:
  • 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, file)

Bases: PIL.ContainerIO.ContainerIO

TiffTags Module

WalImageFile Module

PIL.WalImageFile.open(filename)

_binary Module

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

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)
PIL._binary.i32le(c, o=0)

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)
PIL._binary.o16be(i)
PIL._binary.o16le(i)
PIL._binary.o32be(i)
PIL._binary.o32le(i)
PIL._binary.o8(i)