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)[源代码]

基类:PIL.FontFile.FontFile

PIL.BdfFontFile.bdf_char(f)[源代码]

ContainerIO Module

class PIL.ContainerIO.ContainerIO(file, offset, length)[源代码]

基类:object

isatty()[源代码]
read(n=0)[源代码]

Read data.

参数:n – Number of bytes to read. If omitted or zero, read until end of region.
返回:An 8-bit string.
readline()[源代码]

Read a line of text.

返回:An 8-bit string.
readlines()[源代码]

Read multiple lines of text.

返回:A list of 8-bit strings.
seek(offset, mode=0)[源代码]

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()[源代码]

Get current file pointer.

返回:Offset from start of region, in bytes.

FontFile Module

class PIL.FontFile.FontFile[源代码]

基类:object

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)[源代码]

基类:PIL.ImageFile.ImageFile

format = 'GD'
format_description = 'GD uncompressed images'
PIL.GdImageFile.open(fp, mode='r')[源代码]

Load texture from a GD image file.

参数:
  • filename – 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.

引发:

IOError – If the image could not be read.

GimpGradientFile Module

class PIL.GimpGradientFile.GimpGradientFile(fp)[源代码]

基类:PIL.GimpGradientFile.GradientFile

class PIL.GimpGradientFile.GradientFile[源代码]

基类:object

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)[源代码]

基类:object

getpalette()[源代码]
rawmode = 'RGB'

ImageDraw2 Module

class PIL.ImageDraw2.Brush(color, opacity=255)[源代码]

基类:object

class PIL.ImageDraw2.Draw(image, size=None, color=None)[源代码]

基类:object

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)[源代码]
text(xy, text, font)[源代码]
textsize(text, font)[源代码]
class PIL.ImageDraw2.Font(color, file, size=12)[源代码]

基类:object

class PIL.ImageDraw2.Pen(color, width=1, opacity=255)[源代码]

基类:object

ImageShow Module

class PIL.ImageShow.DisplayViewer[源代码]

基类:PIL.ImageShow.UnixViewer

get_command_ex(file, **options)[源代码]
class PIL.ImageShow.EogViewer[源代码]

基类:PIL.ImageShow.UnixViewer

get_command_ex(file, **options)[源代码]
class PIL.ImageShow.UnixViewer[源代码]

基类:PIL.ImageShow.Viewer

format = 'PNG'
get_command(file, **options)[源代码]
options = {'compress_level': 1}
show_file(file, **options)[源代码]

Display given file

class PIL.ImageShow.Viewer[源代码]

基类:object

Base class for viewers.

format = None
get_command(file, **options)[源代码]
get_format(image)[源代码]

Return format name, or None to save as PGM/PPM

options = {}
save_image(image)[源代码]

Save to temporary file, and return filename

show(image, **options)[源代码]
show_file(file, **options)[源代码]

Display given file

show_image(image, **options)[源代码]

Display given image

class PIL.ImageShow.XVViewer[源代码]

基类:PIL.ImageShow.UnixViewer

get_command_ex(file, title=None, **options)[源代码]
PIL.ImageShow.register(viewer, order=1)[源代码]
PIL.ImageShow.show(image, title=None, **options)[源代码]

Display a given image.

参数:
  • image – An image object.
  • title – Optional title. Not all viewers can display the title.
  • **options – Additional viewer options.
返回:

True if a suitable viewer was found, false otherwise.

PIL.ImageShow.which(executable)[源代码]

ImageTransform Module

class PIL.ImageTransform.AffineTransform(data)[源代码]

基类:PIL.ImageTransform.Transform

Define an affine image transform.

This function takes a 6-tuple (a, b, c, d, e, f) which contain the first two rows from an affine transform matrix. For each pixel (x, y) in the output image, the new value is taken from a position (a x + b y + c, d x + e y + f) in the input image, rounded to nearest pixel.

This function can be used to scale, translate, rotate, and shear the original image.

See transform()

参数:matrix – A 6-tuple (a, b, c, d, e, f) containing the first two rows from an affine transform matrix.
method = 0
class PIL.ImageTransform.ExtentTransform(data)[源代码]

基类:PIL.ImageTransform.Transform

Define a transform to extract a subregion from an image.

Maps a rectangle (defined by two corners) from the image to a rectangle of the given size. The resulting image will contain data sampled from between the corners, such that (x0, y0) in the input image will end up at (0,0) in the output image, and (x1, y1) at size.

This method can be used to crop, stretch, shrink, or mirror an arbitrary rectangle in the current image. It is slightly slower than crop, but about as fast as a corresponding resize operation.

See transform()

参数:bbox – A 4-tuple (x0, y0, x1, y1) which specifies two points in the input image’s coordinate system. See 坐标系统.
method = 1
class PIL.ImageTransform.MeshTransform(data)[源代码]

基类:PIL.ImageTransform.Transform

Define a mesh image transform. A mesh transform consists of one or more individual quad transforms.

See transform()

参数:data – A list of (bbox, quad) tuples.
method = 4
class PIL.ImageTransform.QuadTransform(data)[源代码]

基类:PIL.ImageTransform.Transform

Define a quad image transform.

Maps a quadrilateral (a region defined by four corners) from the image to a rectangle of the given size.

See transform()

参数:xy – An 8-tuple (x0, y0, x1, y1, x2, y2, x3, y3) which contain the upper left, lower left, lower right, and upper right corner of the source quadrilateral.
method = 3
class PIL.ImageTransform.Transform(data)[源代码]

基类: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.: 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_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.: 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)[源代码]

基类:object

getpalette()[源代码]
rawmode = 'RGB'

PcfFontFile Module

class PIL.PcfFontFile.PcfFontFile(fp)[源代码]

基类:PIL.FontFile.FontFile

name = 'name'
PIL.PcfFontFile.sz(s, o)[源代码]

PngImagePlugin.iTXt Class

class PIL.PngImagePlugin.iTXt[源代码]

基类:str

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

__new__(cls, text, lang, tkey)[源代码]
参数:
  • value – value for this key
  • lang – language code
  • tkey – UTF-8 version of the key name

PngImagePlugin.PngInfo Class

class PIL.PngImagePlugin.PngInfo[源代码]

基类:object

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

add(cid, data)[源代码]

Appends an arbitrary chunk. Use with caution.

参数:
  • 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.

参数:
  • 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)[源代码]

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, file)[源代码]

基类:PIL.ContainerIO.ContainerIO

close()[源代码]

WalImageFile Module

PIL.WalImageFile.open(filename)[源代码]

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 <b>putpalette</b> method.

参数:filename – WAL file name, or an opened file handle.
返回:An image instance.

_binary Module

PIL._binary.i16be(c, o=0)[源代码]
PIL._binary.i16le(c, o=0)[源代码]

Converts a 2-bytes (16 bits) string to an unsigned 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 unsigned 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)[源代码]
PIL._binary.si16le(c, o=0)[源代码]

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

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

PIL._binary.si32le(c, o=0)[源代码]

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

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