- PIL Package (autodoc of remaining modules)
- BdfFontFile Module
- ContainerIO Module
- FontFile Module
- GdImageFile Module
- GimpGradientFile Module
- GimpPaletteFile Module
- ImageDraw2 Module
- ImageShow Module
- ImageTransform Module
- JpegPresets Module
- PaletteFile Module
- PcfFontFile Module
- PngImagePlugin.iTXt Class
- PngImagePlugin.PngInfo Class
- TarIO Module
- WalImageFile Module
- _binary Module
PIL Package (autodoc of remaining modules)
Reference for modules whose documentation has not yet been ported or writtencan be found here.
BdfFontFile Module
- class
PIL.BdfFontFile.
BdfFontFile
(fp)[source] - Bases:
PIL.FontFile.FontFile
PIL.BdfFontFile.
bdfchar
(_f)[source]
ContainerIO Module
- class
PIL.ContainerIO.
ContainerIO
(file, offset, length)[source] Bases:
object
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, 1for current offset, and 2 for end of region. You cannot movethe pointer outside the defined region.
tell
()[source]- Get current file pointer.
Returns:Offset from start of region, in bytes.
FontFile Module
- class
PIL.FontFile.
FontFile
[source] Bases:
object
PIL.FontFile.
puti16
(fp, values)[source]
GdImageFile Module
- class
PIL.GdImageFile.
GdImageFile
(fp=None, filename=None)[source] Bases:
PIL.ImageFile.ImageFile
PIL.GdImageFile.
open
(fp, mode='r')[source]- Load texture from a GD image file.
Parameters:
- filename – GD file name, or an opened file handle.
- mode – Optional mode. In this version, if the mode argumentis given, it must be “r”.Returns:
An image instance.
Raises:
IOError – If the image could not be read.
GimpGradientFile Module
- class
PIL.GimpGradientFile.
GimpGradientFile
(fp)[source] - Bases:
PIL.GimpGradientFile.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.
spheredecreasing
(_middle, pos)[source]
PIL.GimpGradientFile.
sphereincreasing
(_middle, pos)[source]
GimpPaletteFile Module
- class
PIL.GimpPaletteFile.
GimpPaletteFile
(fp)[source] Bases:
object
getpalette
()[source]rawmode
= 'RGB'
ImageDraw2 Module
- class
PIL.ImageDraw2.
Brush
(color, opacity=255)[source] - Bases:
object
- class
PIL.ImageDraw2.
Draw
(image, size=None, color=None)[source] Bases:
object
arc
(xy, start, end, *options)[source]chord
(xy, start, end, *options)[source]ellipse
(xy, *options)[source]flush
()[source]line
(xy, *options)[source]pieslice
(xy, start, end, *options)[source]polygon
(xy, *options)[source]rectangle
(xy, *options)[source]render
(op, xy, pen, brush=None)[source]settransform
(offset)[source]text
(xy, text, font)[source]textsize
(text, font)[source]
- class
PIL.ImageDraw2.
Font
(color, file, size=12)[source] - Bases:
object
- class
PIL.ImageDraw2.
Pen
(color, width=1, opacity=255)[source] - Bases:
object
ImageShow Module
- class
PIL.ImageShow.
DisplayViewer
[source] Bases:
PIL.ImageShow.UnixViewer
getcommand_ex
(_file, **options)[source]
- class
PIL.ImageShow.
EogViewer
[source] Bases:
PIL.ImageShow.UnixViewer
getcommand_ex
(_file, **options)[source]
- class
PIL.ImageShow.
UnixViewer
[source] Bases:
PIL.ImageShow.Viewer
- class
PIL.ImageShow.
Viewer
[source] - Bases:
object
Base class for viewers.
format
= Nonegetcommand
(_file, **options)[source]getformat
(_image)[source]Return format name, or None to save as PGM/PPM
saveimage
(_image)[source]Save to temporary file, and return filename
show
(image, **options)[source]showfile
(_file, **options)[source]Display given file
showimage
(_image, **options)[source]- Display given image
- class
PIL.ImageShow.
XVViewer
[source] Bases:
PIL.ImageShow.UnixViewer
getcommand_ex
(_file, title=None, **options)[source]
PIL.ImageShow.
register
(viewer, order=1)[source]
PIL.ImageShow.
show
(image, title=None, **options)[source]- Display a given image.
Parameters:
- image – An image object.
- title – Optional title. Not all viewers can display the title.
- **options – Additional viewer options.Returns:
True if a suitable viewer was found, false otherwise.
ImageTransform Module
- class
PIL.ImageTransform.
AffineTransform
(data)[source] - Bases:
PIL.ImageTransform.Transform
Define an affine image transform.
This function takes a 6-tuple (a, b, c, d, e, f) which contain the firsttwo rows from an affine transform matrix. For each pixel (x, y) in theoutput 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 theoriginal image.
See transform()
Parameters:matrix – A 6-tuple (a, b, c, d, e, f) containing the first two rowsfrom an affine transform matrix.
- class
PIL.ImageTransform.
ExtentTransform
(data)[source] - Bases:
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 ofthe given size. The resulting image will contain data sampled from betweenthe corners, such that (x0, y0) in the input image will end up at (0,0) inthe output image, and (x1, y1) at size.
This method can be used to crop, stretch, shrink, or mirror an arbitraryrectangle in the current image. It is slightly slower than crop, but aboutas fast as a corresponding resize operation.
See transform()
Parameters:bbox – A 4-tuple (x0, y0, x1, y1) which specifies two points in theinput image’s coordinate system. See Coordinate System.
- class
PIL.ImageTransform.
MeshTransform
(data)[source] - Bases:
PIL.ImageTransform.Transform
Define a mesh image transform. A mesh transform consists of one or moreindividual quad transforms.
See transform()
Parameters:data – A list of (bbox, quad) tuples.
- class
PIL.ImageTransform.
QuadTransform
(data)[source] - Bases:
PIL.ImageTransform.Transform
Define a quad image transform.
Maps a quadrilateral (a region defined by four corners) from the image to arectangle of the given size.
See transform()
Parameters:xy – An 8-tuple (x0, y0, x1, y1, x2, y2, x3, y3) which contain theupper left, lower left, lower right, and upper right corner of thesource quadrilateral.
- class
PIL.ImageTransform.
Transform
(data)[source] Bases:
PIL.Image.ImageTransformHandler
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 resolutionfor 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 and4:2:0.
You can get the subsampling of a JPEG with theJpegImagePlugin.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 removeunnecessary 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 dictdirectly as the qtables argument when saving a JPEG.
The tables format between im.quantization and quantization in presets differ in3 ways:
- The base container of the preset is a list with sublists instead of dict.dict[0] -> list[0], dict[1] -> list[1], …
- Each table in a preset is a list instead of an array.
- The zigzag order is remove in the preset (needed by libjpeg >= 6a).
You can convert the dict format to the preset format with theJpegImagePlugin.convert_dict_qtables(dict_qtables) function.
Libjpeg ref.:https://web.archive.org/web/20120328125543/http://www.jpegcameras.com/libjpeg/libjpeg-3.html
PaletteFile Module
PcfFontFile Module
- class
PIL.PcfFontFile.
PcfFontFile
(fp, charset_encoding='iso8859-1')[source] Bases:
PIL.FontFile.FontFile
PIL.PcfFontFile.
sz
(s, o)[source]
PngImagePlugin.iTXt Class
- class
PIL.PngImagePlugin.
iTXt
[source] - Bases:
str
Subclass of string to allow iTXt chunks to look like strings whilekeeping their extra information
new
(cls, text, lang, tkey)[source]
Parameters:
- **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)[source]- Appends an arbitrary chunk. Use with caution.
Parameters:
- **cid** – a byte string, 4 bytes long.
- **data** – a byte string of the encoded data
additxt
(_key, value, lang='', tkey='', zip=False)[source]- 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
addtext
(_key, value, zip=False)[source]- Appends a text chunk.
Parameters:
- **key** – latin-1 encodable text key name
- **value** – value for this key, text or an[<code>PIL.PngImagePlugin.iTXt</code>](#PIL.PngImagePlugin.iTXt) instance
- **zip** – compression flag
TarIO Module
- class
PIL.TarIO.
TarIO
(tarfile, file)[source] Bases:
PIL.ContainerIO.ContainerIO
close
()[source]
WalImageFile Module
PIL.WalImageFile.
open
(filename)[source]- 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 putpalette method.
Parameters:filename – WAL file name, or an opened file handle.Returns:An image instance.
_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