PIL Package

PIL Package

ArgImagePlugin Module

class PIL.ArgImagePlugin.ArgImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'ARG'
format_description = 'Animated raster graphics'
load()[source]
seek(frame)[source]
tell()[source]
verify()[source]

Verify ARG file

class PIL.ArgImagePlugin.ArgStream(fp)[source]

Bases: PIL.PngImagePlugin.ChunkStream

Parser callbacks for ARG data

chunk_ADEF(offset, bytes)[source]

ADEF – store image

chunk_AEND(offset, bytes)[source]

AEND – end of animation

chunk_AFRM(offset, bytes)[source]

AFRM – next frame follows

chunk_AHDR(offset, bytes)[source]

AHDR – animation header

chunk_BLNK(offset, bytes)[source]

BLNK – create blank image

chunk_DEND(offset, bytes)[source]
chunk_DHDR(offset, bytes)[source]

DHDR – delta image follows

chunk_IDAT(offset, bytes)[source]

IDAT – image data block

chunk_IEND(offset, bytes)[source]

IEND – end of image

chunk_IHDR(offset, bytes)[source]

IHDR – full image follows

chunk_JEND(offset, bytes)[source]
chunk_JHDR(offset, bytes)[source]

JHDR – JPEG image follows

chunk_NAME(offset, bytes)[source]

NAME – name the current image

chunk_PAST(offset, bytes)[source]

PAST – paste one image into another

chunk_PLTE(offset, bytes)[source]

PLTE – palette data

chunk_UEND(offset, bytes)[source]
chunk_UHDR(offset, bytes)[source]

UHDR – uncompressed image data follows (EXPERIMENTAL)

chunk_sYNC(offset, bytes)[source]

SYNC – reset decoder

BdfFontFile Module

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

Bases: PIL.FontFile.FontFile

PIL.BdfFontFile.bdf_char(f)[source]

BmpImagePlugin Module

class PIL.BmpImagePlugin.BmpImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'BMP'
format_description = 'Windows Bitmap'
class PIL.BmpImagePlugin.DibImageFile(fp=None, filename=None)[source]

Bases: PIL.BmpImagePlugin.BmpImageFile

format = 'DIB'
format_description = 'Windows Bitmap'

BufrStubImagePlugin Module

class PIL.BufrStubImagePlugin.BufrStubImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.StubImageFile

format = 'BUFR'
format_description = 'BUFR'
PIL.BufrStubImagePlugin.register_handler(handler)[source]

ContainerIO Module

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

CurImagePlugin Module

class PIL.CurImagePlugin.CurImageFile(fp=None, filename=None)[source]

Bases: PIL.BmpImagePlugin.BmpImageFile

format = 'CUR'
format_description = 'Windows Cursor'

DcxImagePlugin Module

class PIL.DcxImagePlugin.DcxImageFile(fp=None, filename=None)[source]

Bases: PIL.PcxImagePlugin.PcxImageFile

format = 'DCX'
format_description = 'Intel DCX'
seek(frame)[source]
tell()[source]

EpsImagePlugin Module

class PIL.EpsImagePlugin.EpsImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

EPS File Parser for the Python Imaging Library

format = 'EPS'
format_description = 'Encapsulated Postscript'
load()[source]
PIL.EpsImagePlugin.Ghostscript(tile, size, fp)[source]

Render an image using Ghostscript

class PIL.EpsImagePlugin.PSFile(fp)[source]

Wrapper that treats either CR or LF as end of line.

read(count)[source]
readline()[source]
seek(offset, whence=0)[source]
tell()[source]

ExifTags Module

FitsStubImagePlugin Module

class PIL.FitsStubImagePlugin.FITSStubImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.StubImageFile

format = 'FITS'
format_description = 'FITS'
PIL.FitsStubImagePlugin.register_handler(handler)[source]

FliImagePlugin Module

class PIL.FliImagePlugin.FliImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'FLI'
format_description = 'Autodesk FLI/FLC Animation'
seek(frame)[source]
tell()[source]

FontFile Module

class PIL.FontFile.FontFile[source]
bitmap = None
compile()[source]

Create metrics and bitmap

save(filename)

Save font in version 1 format

save1(filename)[source]

Save font in version 1 format

save2(filename)[source]

Save font in version 2 format

PIL.FontFile.puti16(fp, values)[source]

FpxImagePlugin Module

class PIL.FpxImagePlugin.FpxImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'FPX'
format_description = 'FlashPix'
load()[source]

GbrImagePlugin Module

class PIL.GbrImagePlugin.GbrImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'GBR'
format_description = 'GIMP brush file'
load()[source]

GdImageFile Module

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

Bases: PIL.ImageFile.ImageFile

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

GifImagePlugin Module

class PIL.GifImagePlugin.GifImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

data()[source]
format = 'GIF'
format_description = 'Compuserve GIF'
global_palette = None
seek(frame)[source]
tell()[source]
PIL.GifImagePlugin.getdata(im, offset=(0, 0), **params)[source]

Return a list of strings representing this image. The first string is a local image header, the rest contains encoded image data.

PIL.GifImagePlugin.getheader(im, palette=None, info=None)[source]

Return a list of strings representing a GIF header

GimpGradientFile Module

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

Bases: PIL.GimpGradientFile.GradientFile

class PIL.GimpGradientFile.GradientFile[source]
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]
getpalette()[source]
rawmode = 'RGB'

GribStubImagePlugin Module

class PIL.GribStubImagePlugin.GribStubImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.StubImageFile

format = 'GRIB'
format_description = 'GRIB'
PIL.GribStubImagePlugin.register_handler(handler)[source]

Hdf5StubImagePlugin Module

class PIL.Hdf5StubImagePlugin.HDF5StubImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.StubImageFile

format = 'HDF5'
format_description = 'HDF5'
PIL.Hdf5StubImagePlugin.register_handler(handler)[source]

IcnsImagePlugin Module

class PIL.IcnsImagePlugin.IcnsFile(fobj)[source]
SIZES = {(16, 16): [('is32', <function read_32 at 0x18e28b0>), ('s8mk', <function read_mk at 0x18e23f0>)], (48, 48): [('ih32', <function read_32 at 0x18e28b0>), ('h8mk', <function read_mk at 0x18e23f0>)], (128, 128): [('it32', <function read_32t at 0x18e2370>), ('t8mk', <function read_mk at 0x18e23f0>)], (32, 32): [('il32', <function read_32 at 0x18e28b0>), ('l8mk', <function read_mk at 0x18e23f0>)]}
bestsize()[source]
dataforsize(size)[source]

Get an icon resource as {channel: array}. Note that the arrays are bottom-up like windows bitmaps and will likely need to be flipped or transposed in some way.

getimage(size=None)[source]
itersizes()[source]
class PIL.IcnsImagePlugin.IcnsImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

PIL read-only image support for Mac OS .icns files. Chooses the best resolution, but will possibly load a different size image if you mutate the size attribute before calling ‘load’.

The info dictionary has a key ‘sizes’ that is a list of sizes that the icns file has.

format = 'ICNS'
format_description = 'Mac OS icns resource'
load()[source]
PIL.IcnsImagePlugin.nextheader(fobj)[source]
PIL.IcnsImagePlugin.read_32(fobj, start_length, size)[source]

Read a 32bit RGB icon resource. Seems to be either uncompressed or an RLE packbits-like scheme.

PIL.IcnsImagePlugin.read_32t(fobj, start_length, size)[source]
PIL.IcnsImagePlugin.read_mk(fobj, start_length, size)[source]

IcoImagePlugin Module

class PIL.IcoImagePlugin.IcoFile(buf)[source]
frame(idx)[source]

Get an image from frame idx

getimage(size, bpp=False)[source]

Get an image from the icon

sizes()[source]

Get a list of all available icon sizes and color depths.

class PIL.IcoImagePlugin.IcoImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

PIL read-only image support for Microsoft Windows .ico files.

By default the largest resolution image in the file will be loaded. This can be changed by altering the ‘size’ attribute before calling ‘load’.

The info dictionary has a key ‘sizes’ that is a list of the sizes available in the icon file.

Handles classic, XP and Vista icon formats.

This plugin is a refactored version of Win32IconImagePlugin by Bryan Davis <casadebender@gmail.com>. https://code.google.com/p/casadebender/wiki/Win32IconImagePlugin

format = 'ICO'
format_description = 'Windows Icon'
load()[source]

ImImagePlugin Module

class PIL.ImImagePlugin.ImImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'IM'
format_description = 'IFUNC Image Memory'
seek(frame)[source]
tell()[source]
PIL.ImImagePlugin.number(s)[source]

Image Module

class PIL.Image.Image[source]

This class represents an image object. To create Image objects, use the appropriate factory functions. There’s hardly ever any reason to call the Image constructor directly.

convert(mode=None, data=None, dither=None, palette=0, colors=256)[source]

Returns a converted copy of this image. For the “P” mode, this method translates pixels through the palette. If mode is omitted, a mode is chosen so that all information in the image and the palette can be represented without a palette.

The current version supports all possible conversions between “L”, “RGB” and “CMYK.”

When translating a colour image to black and white (mode “L”), the library uses the ITU-R 601-2 luma transform:

L = R * 299/1000 + G * 587/1000 + B * 114/1000

When translating a greyscale image into a bilevel image (mode “1”), all non-zero values are set to 255 (white). To use other thresholds, use the PIL.Image.Image.point() method.

Parameters:
  • mode – The requested mode.
  • matrix – An optional conversion matrix. If given, this should be 4- or 16-tuple containing floating point values.
  • dither – Dithering method, used when converting from mode “RGB” to “P”. Available methods are NONE or FLOYDSTEINBERG (default).
  • palette – Palette to use when converting from mode “RGB” to “P”. Available palettes are WEB or ADAPTIVE.
  • colors – Number of colors to use for the ADAPTIVE palette. Defaults to 256.
Return type:

PIL.Image.Image

Returns:

An Image object.

copy()[source]

Copies this image. Use this method if you wish to paste things into an image, but still retain the original.

Return type:PIL.Image.Image
Returns:An Image object.
crop(box=None)[source]

Returns a rectangular region from this image. The box is a 4-tuple defining the left, upper, right, and lower pixel coordinate.

This is a lazy operation. Changes to the source image may or may not be reflected in the cropped image. To break the connection, call the {@link #Image.load} method on the cropped copy.

Parameters:box – The crop rectangle, as a (left, upper, right, lower)-tuple.
Return type:PIL.Image.Image
Returns:An Image object.
draft(mode, size)[source]

Configures the image file loader so it returns a version of the image that as closely as possible matches the given mode and size. For example, you can use this method to convert a colour JPEG to greyscale while loading it, or to extract a 128x192 version from a PCD file.

Note that this method modifies the Image object in place. If the image has already been loaded, this method has no effect.

Parameters:
  • mode – The requested mode.
  • size – The requested size.
filter(filter)[source]

Filters this image using the given filter. For a list of available filters, see the PIL.ImageFilter module.

Parameters:filter – Filter kernel.
Returns:An Image object.
format = None
format_description = None
frombytes(data, decoder_name='raw', *args)[source]

Loads this image with pixel data from a bytes object.

This method is similar to the PIL.Image.frombytes() function, but loads data into this image instead of creating a new image object.

fromstring(*args, **kw)[source]

Deprecated alias to frombytes

getbands()[source]

Returns a tuple containing the name of each band in this image. For example, getbands on an RGB image returns (“R”, “G”, “B”).

Returns:A tuple containing band names.
Return type:tuple
getbbox()[source]

Calculates the bounding box of the non-zero regions in the image.

Returns:The bounding box is returned as a 4-tuple defining the left, upper, right, and lower pixel coordinate. If the image is completely empty, this method returns None.
getcolors(maxcolors=256)[source]

Returns a list of colors used in this image.

Parameters:maxcolors – Maximum number of colors. If this number is exceeded, this method returns None. The default limit is 256 colors.
Returns:An unsorted list of (count, pixel) values.
getdata(band=None)[source]

Returns the contents of this image as a sequence object containing pixel values. The sequence object is flattened, so that values for line one follow directly after the values of line zero, and so on.

Note that the sequence object returned by this method is an internal PIL data type, which only supports certain sequence operations. To convert it to an ordinary sequence (e.g. for printing), use list(im.getdata()).

Parameters:band – What band to return. The default is to return all bands. To return a single band, pass in the index value (e.g. 0 to get the “R” band from an “RGB” image).
Returns:A sequence-like object.
getextrema()[source]

Gets the the minimum and maximum pixel values for each band in the image.

Returns:For a single-band image, a 2-tuple containing the minimum and maximum pixel value. For a multi-band image, a tuple containing one 2-tuple for each band.
getim()[source]

Returns a capsule that points to the internal image memory.

Returns:A capsule object.
getpalette()[source]

Returns the image palette as a list.

Returns:A list of color values [r, g, b, ...], or None if the image has no palette.
getpixel(xy)[source]

Returns the pixel value at a given position.

Parameters:xy – The coordinate, given as (x, y).
Returns:The pixel value. If the image is a multi-layer image, this method returns a tuple.
getprojection()[source]

Get projection to x and y axes

Returns:Two sequences, indicating where there are non-zero pixels along the X-axis and the Y-axis, respectively.
histogram(mask=None, extrema=None)[source]

Returns a histogram for the image. The histogram is returned as a list of pixel counts, one for each pixel value in the source image. If the image has more than one band, the histograms for all bands are concatenated (for example, the histogram for an “RGB” image contains 768 values).

A bilevel image (mode “1”) is treated as a greyscale (“L”) image by this method.

If a mask is provided, the method returns a histogram for those parts of the image where the mask image is non-zero. The mask image must have the same size as the image, and be either a bi-level image (mode “1”) or a greyscale image (“L”).

Parameters:mask – An optional mask.
Returns:A list containing pixel counts.
load()[source]

Allocates storage for the image and loads the pixel data. In normal cases, you don’t need to call this method, since the Image class automatically loads an opened image when it is accessed for the first time.

Returns:An image access object.
offset(xoffset, yoffset=None)[source]

(Deprecated) Returns a copy of the image where the data has been offset by the given distances. Data wraps around the edges. If yoffset is omitted, it is assumed to be equal to xoffset.

This method is deprecated. New code should use the PIL.ImageChops.offset() function in the PIL.ImageChops module.

Parameters:
  • xoffset – The horizontal distance.
  • yoffset – The vertical distance. If omitted, both distances are set to the same value.
Returns:

An Image object.

paste(im, box=None, mask=None)[source]

Pastes another image into this image. The box argument is either a 2-tuple giving the upper left corner, a 4-tuple defining the left, upper, right, and lower pixel coordinate, or None (same as (0, 0)). If a 4-tuple is given, the size of the pasted image must match the size of the region.

If the modes don’t match, the pasted image is converted to the mode of this image (see the PIL.Image.Image.convert() method for details).

Instead of an image, the source can be a integer or tuple containing pixel values. The method then fills the region with the given colour. When creating RGB images, you can also use colour strings as supported by the ImageColor module.

If a mask is given, this method updates only the regions indicated by the mask. You can use either “1”, “L” or “RGBA” images (in the latter case, the alpha band is used as mask). Where the mask is 255, the given image is copied as is. Where the mask is 0, the current value is preserved. Intermediate values can be used for transparency effects.

Note that if you paste an “RGBA” image, the alpha band is ignored. You can work around this by using the same image as both source image and mask.

Parameters:
  • im – Source image or pixel value (integer or tuple).
  • box

    An optional 4-tuple giving the region to paste into. If a 2-tuple is used instead, it’s treated as the upper left corner. If omitted or None, the source is pasted into the upper left corner.

    If an image is given as the second argument and there is no third, the box defaults to (0, 0), and the second argument is interpreted as a mask image.

  • mask – An optional mask image.
Returns:

An Image object.

point(lut, mode=None)[source]

Maps this image through a lookup table or function.

Parameters:
  • lut – A lookup table, containing 256 values per band in the image. A function can be used instead, it should take a single argument. The function is called once for each possible pixel value, and the resulting table is applied to all bands of the image.
  • mode – Output mode (default is same as input). In the current version, this can only be used if the source image has mode “L” or “P”, and the output has mode “1”.
Returns:

An Image object.

putalpha(alpha)[source]

Adds or replaces the alpha layer in this image. If the image does not have an alpha layer, it’s converted to “LA” or “RGBA”. The new layer must be either “L” or “1”.

Parameters:alpha – The new alpha layer. This can either be an “L” or “1” image having the same size as this image, or an integer or other color value.
putdata(data, scale=1.0, offset=0.0)[source]

Copies pixel data to this image. This method copies data from a sequence object into the image, starting at the upper left corner (0, 0), and continuing until either the image or the sequence ends. The scale and offset values are used to adjust the sequence values: pixel = value*scale + offset.

Parameters:
  • data – A sequence object.
  • scale – An optional scale value. The default is 1.0.
  • offset – An optional offset value. The default is 0.0.
putpalette(data, rawmode='RGB')[source]

Attaches a palette to this image. The image must be a “P” or “L” image, and the palette sequence must contain 768 integer values, where each group of three values represent the red, green, and blue values for the corresponding pixel index. Instead of an integer sequence, you can use an 8-bit string.

Parameters:data – A palette sequence (either a list or a string).
putpixel(xy, value)[source]

Modifies the pixel at the given position. The colour is given as a single numerical value for single-band images, and a tuple for multi-band images.

Note that this method is relatively slow. For more extensive changes, use PIL.Image.Image.paste() or the PIL.ImageDraw module instead.

See:

Parameters:
  • xy – The pixel coordinate, given as (x, y).
  • value – The pixel value.
quantize(colors=256, method=0, kmeans=0, palette=None)[source]
resize(size, resample=0)[source]

Returns a resized copy of this image.

Parameters:
  • size – The requested size in pixels, as a 2-tuple: (width, height).
  • filter – An optional resampling filter. This can be one of PIL.Image.NEAREST (use nearest neighbour), PIL.Image.BILINEAR (linear interpolation in a 2x2 environment), PIL.Image.BICUBIC (cubic spline interpolation in a 4x4 environment), or PIL.Image.ANTIALIAS (a high-quality downsampling filter). If omitted, or if the image has mode “1” or “P”, it is set PIL.Image.NEAREST.
Returns:

An Image object.

rotate(angle, resample=0, expand=0)[source]

Returns a rotated copy of this image. This method returns a copy of this image, rotated the given number of degrees counter clockwise around its centre.

Parameters:
  • angle – In degrees counter clockwise.
  • filter – An optional resampling filter. This can be one of PIL.Image.NEAREST (use nearest neighbour), PIL.Image.BILINEAR (linear interpolation in a 2x2 environment), or PIL.Image.BICUBIC (cubic spline interpolation in a 4x4 environment). If omitted, or if the image has mode “1” or “P”, it is set PIL.Image.NEAREST.
  • expand – Optional expansion flag. If true, expands the output image to make it large enough to hold the entire rotated image. If false or omitted, make the output image the same size as the input image.
Returns:

An Image object.

save(fp, format=None, **params)[source]

Saves this image under the given filename. If no format is specified, the format to use is determined from the filename extension, if possible.

Keyword options can be used to provide additional instructions to the writer. If a writer doesn’t recognise an option, it is silently ignored. The available options are described later in this handbook.

You can use a file object instead of a filename. In this case, you must always specify the format. The file object must implement the seek, tell, and write methods, and be opened in binary mode.

Parameters:
  • file – File name or file object.
  • format – Optional format override. If omitted, the format to use is determined from the filename extension. If a file object was used instead of a filename, this parameter should always be used.
  • options – Extra parameters to the image writer.
Returns:

None

Raises:
  • KeyError – If the output format could not be determined from the file name. Use the format option to solve this.
  • IOError – If the file could not be written. The file may have been created, and may contain partial data.
seek(frame)[source]

Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an EOFError exception. When a sequence file is opened, the library automatically seeks to frame 0.

Note that in the current version of the library, most sequence formats only allows you to seek to the next frame.

See PIL.Image.Image.tell().

Parameters:frame – Frame number, starting at 0.
Raises EOFError:
 If the call attempts to seek beyond the end of the sequence.
show(title=None, command=None)[source]

Displays this image. This method is mainly intended for debugging purposes.

On Unix platforms, this method saves the image to a temporary PPM file, and calls the xv utility.

On Windows, it saves the image to a temporary BMP file, and uses the standard BMP display utility to show it (usually Paint).

Parameters:
  • title – Optional title to use for the image window, where possible.
  • command – command used to show the image
split()[source]

Split this image into individual bands. This method returns a tuple of individual image bands from an image. For example, splitting an “RGB” image creates three new images each containing a copy of one of the original bands (red, green, blue).

Returns:A tuple containing bands.
tell()[source]

Returns the current frame number. See PIL.Image.Image.seek().

Returns:Frame number, starting with 0.
thumbnail(size, resample=0)[source]

Make this image into a thumbnail. This method modifies the image to contain a thumbnail version of itself, no larger than the given size. This method calculates an appropriate thumbnail size to preserve the aspect of the image, calls the PIL.Image.Image.draft() method to configure the file reader (where applicable), and finally resizes the image.

Note that the bilinear and bicubic filters in the current version of PIL are not well-suited for thumbnail generation. You should use PIL.Image.ANTIALIAS unless speed is much more important than quality.

Also note that this function modifies the Image object in place. If you need to use the full resolution image as well, apply this method to a PIL.Image.Image.copy() of the original image.

Parameters:
  • size – Requested size.
  • resample – Optional resampling filter. This can be one of PIL.Image.NEAREST, PIL.Image.BILINEAR, PIL.Image.BICUBIC, or PIL.Image.ANTIALIAS (best quality). If omitted, it defaults to PIL.Image.NEAREST (this will be changed to ANTIALIAS in a future version).
Returns:

None

tobitmap(name='image')[source]

Returns the image converted to an X11 bitmap.

Note

This method only works for mode “1” images.

Parameters:name – The name prefix to use for the bitmap variables.
Returns:A string containing an X11 bitmap.
Raises ValueError:
 If the mode is not “1”
tobytes(encoder_name='raw', *args)[source]

Return image as a bytes object

Parameters:
  • encoder_name – What encoder to use. The default is to use the standard “raw” encoder.
  • args – Extra arguments to the encoder.
Return type:

A bytes object.

tostring(*args, **kw)[source]
transform(size, method, data=None, resample=0, fill=1)[source]

Transforms this image. This method creates a new image with the given size, and the same mode as the original, and copies data to the new image using the given transform.

Parameters:
  • size – The output size.
  • method – The transformation method. This is one of PIL.Image.EXTENT (cut out a rectangular subregion), PIL.Image.AFFINE (affine transform), PIL.Image.PERSPECTIVE (perspective transform), PIL.Image.QUAD (map a quadrilateral to a rectangle), or PIL.Image.MESH (map a number of source quadrilaterals in one operation).
  • data – Extra data to the transformation method.
  • resample – Optional resampling filter. It can be one of PIL.Image.NEAREST (use nearest neighbour), PIL.Image.BILINEAR (linear interpolation in a 2x2 environment), or PIL.Image.BICUBIC (cubic spline interpolation in a 4x4 environment). If omitted, or if the image has mode “1” or “P”, it is set to PIL.Image.NEAREST.
Returns:

An Image object.

transpose(method)[source]

Transpose image (flip or rotate in 90 degree steps)

Parameters:method – One of PIL.Image.FLIP_LEFT_RIGHT, PIL.Image.FLIP_TOP_BOTTOM, PIL.Image.ROTATE_90, PIL.Image.ROTATE_180, or PIL.Image.ROTATE_270.
Returns:Returns a flipped or rotated copy of this image.
verify()[source]

Verifies the contents of a file. For data read from a file, this method attempts to determine if the file is broken, without actually decoding the image data. If this method finds any problems, it raises suitable exceptions. If you need to load the image after using this method, you must reopen the image file.

class PIL.Image.ImagePointHandler[source]
class PIL.Image.ImageTransformHandler[source]
PIL.Image.alpha_composite(im1, im2)[source]

Alpha composite im2 over im1.

Parameters:
  • im1 – The first image.
  • im2 – The second image. Must have the same mode and size as the first image.
Returns:

An Image object.

PIL.Image.blend(im1, im2, alpha)[source]

Creates a new image by interpolating between two input images, using a constant alpha.:

out = image1 * (1.0 - alpha) + image2 * alpha
Parameters:
  • im1 – The first image.
  • im2 – The second image. Must have the same mode and size as the first image.
  • alpha – The interpolation alpha factor. If alpha is 0.0, a copy of the first image is returned. If alpha is 1.0, a copy of the second image is returned. There are no restrictions on the alpha value. If necessary, the result is clipped to fit into the allowed output range.
Returns:

An Image object.

PIL.Image.coerce_e(value)[source]
PIL.Image.composite(image1, image2, mask)[source]

Create composite image by blending images using a transparency mask.

Parameters:
  • image1 – The first image.
  • image2 – The second image. Must have the same mode and size as the first image.
  • mask – A mask image. This image can can have mode “1”, “L”, or “RGBA”, and must have the same size as the other two images.
PIL.Image.eval(image, *args)[source]

Applies the function (which should take one argument) to each pixel in the given image. If the image has more than one band, the same function is applied to each band. Note that the function is evaluated once for each possible pixel value, so you cannot use random components or other generators.

Parameters:
  • image – The input image.
  • function – A function object, taking one integer argument.
Returns:

An Image object.

PIL.Image.fromarray(obj, mode=None)[source]

Creates an image memory from an object exporting the array interface (using the buffer protocol).

If obj is not contiguous, then the tobytes method is called and PIL.Image.frombuffer() is used.

Parameters:
  • obj – Object with array interface
  • mode – Mode to use (will be determined from type if None)
Returns:

An image memory.

New in version 1.1.6.

PIL.Image.frombuffer(mode, size, data, decoder_name='raw', *args)[source]

Creates an image memory referencing pixel data in a byte buffer.

This function is similar to PIL.Image.frombytes(), but uses data in the byte buffer, where possible. This means that changes to the original buffer object are reflected in this image). Not all modes can share memory; supported modes include “L”, “RGBX”, “RGBA”, and “CMYK”.

Note that this function decodes pixel data only, not entire images. If you have an entire image file in a string, wrap it in a BytesIO object, and use PIL.Image.open() to load it.

In the current version, the default parameters used for the “raw” decoder differs from that used for PIL.Image.fromstring(). This is a bug, and will probably be fixed in a future release. The current release issues a warning if you do this; to disable the warning, you should provide the full set of parameters. See below for details.

Parameters:
  • mode – The image mode.
  • size – The image size.
  • data – A bytes or other buffer object containing raw data for the given mode.
  • decoder_name – What decoder to use.
  • args

    Additional parameters for the given decoder. For the default encoder (“raw”), it’s recommended that you provide the full set of parameters:

    frombuffer(mode, size, data, "raw", mode, 0, 1)
    
Returns:

An Image object.

New in version 1.1.4.

PIL.Image.frombytes(mode, size, data, decoder_name='raw', *args)[source]

Creates a copy of an image memory from pixel data in a buffer.

In its simplest form, this function takes three arguments (mode, size, and unpacked pixel data).

You can also use any pixel decoder supported by PIL. For more information on available decoders, see the section Writing Your Own File Decoder.

Note that this function decodes pixel data only, not entire images. If you have an entire image in a string, wrap it in a BytesIO object, and use PIL.Image.open() to load it.

Parameters:
  • mode – The image mode.
  • size – The image size.
  • data – A byte buffer containing raw data for the given mode.
  • decoder_name – What decoder to use.
  • args – Additional parameters for the given decoder.
Returns:

An Image object.

PIL.Image.fromstring(*args, **kw)[source]

Deprecated alias to frombytes

PIL.Image.getmodebandnames(mode)[source]

Gets a list of individual band names. Given a mode, this function returns a tuple containing the names of individual bands (use PIL.Image.getmodetype() to get the mode used to store each individual band.

Parameters:mode – Input mode.
Returns:A tuple containing band names. The length of the tuple gives the number of bands in an image of the given mode.
Raises KeyError:
 If the input mode was not a standard mode.
PIL.Image.getmodebands(mode)[source]

Gets the number of individual bands for this mode.

Parameters:mode – Input mode.
Returns:The number of bands in this mode.
Raises KeyError:
 If the input mode was not a standard mode.
PIL.Image.getmodebase(mode)[source]

Gets the “base” mode for given mode. This function returns “L” for images that contain grayscale data, and “RGB” for images that contain color data.

Parameters:mode – Input mode.
Returns:“L” or “RGB”.
Raises KeyError:
 If the input mode was not a standard mode.
PIL.Image.getmodetype(mode)[source]

Gets the storage type mode. Given a mode, this function returns a single-layer mode suitable for storing individual bands.

Parameters:mode – Input mode.
Returns:“L”, “I”, or “F”.
Raises KeyError:
 If the input mode was not a standard mode.
PIL.Image.init()[source]

Explicitly initializes the Python Imaging Library. This function loads all available file format drivers.

PIL.Image.isImageType(t)[source]

Checks if an object is an image object.

Warning

This function is for internal use only.

Parameters:t – object to check if it’s an image
Returns:True if the object is an image
PIL.Image.merge(mode, bands)[source]

Merge a set of single band images into a new multiband image.

Parameters:
  • mode – The mode to use for the output image.
  • bands – A sequence containing one single-band image for each band in the output image. All bands must have the same size.
Returns:

An Image object.

PIL.Image.new(mode, size, color=0)[source]

Creates a new image with the given mode and size.

Parameters:
  • mode – The mode to use for the new image.
  • size – A 2-tuple, containing (width, height) in pixels.
  • color – What colour to use for the image. Default is black. If given, this should be a single integer or floating point value for single-band modes, and a tuple for multi-band modes (one value per band). When creating RGB images, you can also use colour strings as supported by the ImageColor module. If the colour is None, the image is not initialised.
Returns:

An Image object.

PIL.Image.open(fp, mode='r')[source]

Opens and identifies the given image file.

This is a lazy operation; this function identifies the file, but the actual image data is not read from the file until you try to process the data (or call the PIL.Image.Image.load() method). See PIL.Image.new()

Parameters:
  • file – A filename (string) or a file object. The file object must implement read, seek, and tell methods, and be opened in binary mode.
  • mode – The mode. If given, this argument must be “r”.
Returns:

An Image object.

Raises IOError:

If the file cannot be found, or the image cannot be opened and identified.

PIL.Image.preinit()[source]

Explicitly load standard file format drivers.

PIL.Image.register_extension(id, extension)[source]

Registers an image extension. This function should not be used in application code.

Parameters:
  • id – An image format identifier.
  • extension – An extension used for this format.
PIL.Image.register_mime(id, mimetype)[source]

Registers an image MIME type. This function should not be used in application code.

Parameters:
  • id – An image format identifier.
  • mimetype – The image MIME type for this format.
PIL.Image.register_open(id, factory, accept=None)[source]

Register an image file plugin. This function should not be used in application code.

Parameters:
  • id – An image format identifier.
  • factory – An image file factory method.
  • accept – An optional function that can be used to quickly reject images having another format.
PIL.Image.register_save(id, driver)[source]

Registers an image save function. This function should not be used in application code.

Parameters:
  • id – An image format identifier.
  • driver – A function to save images in this format.

ImageChops Module

PIL.ImageChops.add(image1, image2, scale=1.0, offset=0)[source]

Add two images

PIL.ImageChops.add_modulo(image1, image2)[source]

Add two images without clipping

PIL.ImageChops.blend(image1, image2, alpha)[source]

Blend two images using a constant transparency weight

PIL.ImageChops.composite(image1, image2, mask)[source]

Create composite image by blending images using a transparency mask

PIL.ImageChops.constant(image, value)[source]

Fill a channel with a given grey level

PIL.ImageChops.darker(image1, image2)[source]

Select the darker pixels from each image

PIL.ImageChops.difference(image1, image2)[source]

Subtract one image from another

PIL.ImageChops.duplicate(image)[source]

Create a copy of a channel

PIL.ImageChops.invert(image)[source]

Invert a channel

PIL.ImageChops.lighter(image1, image2)[source]

Select the lighter pixels from each image

PIL.ImageChops.logical_and(image1, image2)[source]

Logical and between two images

PIL.ImageChops.logical_or(image1, image2)[source]

Logical or between two images

PIL.ImageChops.logical_xor(image1, image2)[source]

Logical xor between two images

PIL.ImageChops.multiply(image1, image2)[source]

Superimpose two positive images

PIL.ImageChops.offset(image, xoffset, yoffset=None)[source]

Offset image in horizontal and/or vertical direction

PIL.ImageChops.screen(image1, image2)[source]

Superimpose two negative images

PIL.ImageChops.subtract(image1, image2, scale=1.0, offset=0)[source]

Subtract two images

PIL.ImageChops.subtract_modulo(image1, image2)[source]

Subtract two images without clipping

ImageCms Module

class PIL.ImageCms.ImageCmsProfile(profile)[source]
class PIL.ImageCms.ImageCmsTransform(input, output, input_mode, output_mode, intent=0, proof=None, proof_intent=3, flags=0)[source]

Bases: PIL.Image.ImagePointHandler

apply(im, imOut=None)[source]
apply_in_place(im)[source]
point(im)[source]
exception PIL.ImageCms.PyCMSError[source]

Bases: exceptions.Exception

PIL.ImageCms.applyTransform(im, transform, inPlace=0)[source]
PIL.ImageCms.buildProofTransform(inputProfile, outputProfile, proofProfile, inMode, outMode, renderingIntent=0, proofRenderingIntent=3, flags=16384)[source]
PIL.ImageCms.buildProofTransformFromOpenProfiles(inputProfile, outputProfile, proofProfile, inMode, outMode, renderingIntent=0, proofRenderingIntent=3, flags=16384)
PIL.ImageCms.buildTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent=0, flags=0)[source]
PIL.ImageCms.buildTransformFromOpenProfiles(inputProfile, outputProfile, inMode, outMode, renderingIntent=0, flags=0)
PIL.ImageCms.createProfile(colorSpace, colorTemp=-1)[source]
PIL.ImageCms.getDefaultIntent(profile)[source]
PIL.ImageCms.getOpenProfile(profileFilename)[source]
PIL.ImageCms.getProfileInfo(profile)[source]
PIL.ImageCms.getProfileName(profile)[source]
PIL.ImageCms.get_display_profile(handle=None)[source]
PIL.ImageCms.isIntentSupported(profile, intent, direction)[source]
PIL.ImageCms.profileToProfile(im, inputProfile, outputProfile, renderingIntent=0, outputMode=None, inPlace=0, flags=0)[source]
PIL.ImageCms.versions()[source]

ImageColor Module

PIL.ImageColor.getcolor(color, mode)[source]
PIL.ImageColor.getrgb(color)[source]

ImageDraw Module

PIL.ImageDraw.Draw(im, mode=None)[source]
class PIL.ImageDraw.ImageDraw(im, mode=None)[source]
arc(xy, start, end, fill=None)[source]
bitmap(xy, bitmap, fill=None)[source]
chord(xy, start, end, fill=None, outline=None)[source]
ellipse(xy, fill=None, outline=None)[source]
getfont()[source]
line(xy, fill=None, width=0)[source]
pieslice(xy, start, end, fill=None, outline=None)[source]
point(xy, fill=None)[source]
polygon(xy, fill=None, outline=None)[source]
rectangle(xy, fill=None, outline=None)[source]
setfill(onoff)[source]
setfont(font)[source]
setink(ink)[source]
shape(shape, fill=None, outline=None)[source]
text(xy, text, fill=None, font=None, anchor=None)[source]
textsize(text, font=None)[source]
PIL.ImageDraw.floodfill(image, xy, value, border=None)[source]

Fill bounded region.

PIL.ImageDraw.getdraw(im=None, hints=None)[source]

ImageDraw2 Module

class PIL.ImageDraw2.Brush(color, opacity=255)[source]
class PIL.ImageDraw2.Draw(image, size=None, color=None)[source]
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]
symbol(xy, symbol, *options)[source]
text(xy, text, font)[source]
textsize(text, font)[source]
class PIL.ImageDraw2.Font(color, file, size=12)[source]
class PIL.ImageDraw2.Pen(color, width=1, opacity=255)[source]

ImageEnhance Module

class PIL.ImageEnhance.Brightness(image)[source]

Bases: PIL.ImageEnhance._Enhance

Adjust image brightness

class PIL.ImageEnhance.Color(image)[source]

Bases: PIL.ImageEnhance._Enhance

Adjust image colour balance

class PIL.ImageEnhance.Contrast(image)[source]

Bases: PIL.ImageEnhance._Enhance

Adjust image contrast

class PIL.ImageEnhance.Sharpness(image)[source]

Bases: PIL.ImageEnhance._Enhance

Adjust image sharpness

ImageFile Module

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

Bases: PIL.Image.Image

Base class for image file format handlers.

draft(mode, size)[source]

Set draft mode

load()[source]

Load image data based on tile list

load_end()[source]
load_prepare()[source]
verify()[source]

Check file integrity

class PIL.ImageFile.Parser[source]

Incremental image parser. This class implements the standard feed/close consumer interface.

close()[source]

(Consumer) Close the stream.

Returns:An image object.
Raises IOError:If the parser failed to parse the image file.
data = None
decoder = None
feed(data)[source]

(Consumer) Feed data to the parser.

:param data” A string buffer. :exception IOError: If the parser failed to parse the image file.

finished = 0
image = None
incremental = None
reset()[source]

(Consumer) Reset the parser. Note that you can only call this method immediately after you’ve created a parser; parser instances cannot be reused.

class PIL.ImageFile.StubImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

Base class for stub image loaders.

A stub loader is an image loader that can identify files of a certain format, but relies on external code to load the file.

load()[source]
PIL.ImageFile.raise_ioerror(error)[source]

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)[source]

Bases: _io.BytesIO

ImageFilter Module

class PIL.ImageFilter.BLUR[source]

Bases: PIL.ImageFilter.BuiltinFilter

filterargs = ((5, 5), 16, 0, (1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1))
name = 'Blur'
class PIL.ImageFilter.BuiltinFilter[source]

Bases: PIL.ImageFilter.Kernel

class PIL.ImageFilter.CONTOUR[source]

Bases: PIL.ImageFilter.BuiltinFilter

filterargs = ((3, 3), 1, 255, (-1, -1, -1, -1, 8, -1, -1, -1, -1))
name = 'Contour'
class PIL.ImageFilter.DETAIL[source]

Bases: PIL.ImageFilter.BuiltinFilter

filterargs = ((3, 3), 6, 0, (0, -1, 0, -1, 10, -1, 0, -1, 0))
name = 'Detail'
class PIL.ImageFilter.EDGE_ENHANCE[source]

Bases: PIL.ImageFilter.BuiltinFilter

filterargs = ((3, 3), 2, 0, (-1, -1, -1, -1, 10, -1, -1, -1, -1))
name = 'Edge-enhance'
class PIL.ImageFilter.EDGE_ENHANCE_MORE[source]

Bases: PIL.ImageFilter.BuiltinFilter

filterargs = ((3, 3), 1, 0, (-1, -1, -1, -1, 9, -1, -1, -1, -1))
name = 'Edge-enhance More'
class PIL.ImageFilter.EMBOSS[source]

Bases: PIL.ImageFilter.BuiltinFilter

filterargs = ((3, 3), 1, 128, (-1, 0, 0, 0, 1, 0, 0, 0, 0))
name = 'Emboss'
class PIL.ImageFilter.FIND_EDGES[source]

Bases: PIL.ImageFilter.BuiltinFilter

filterargs = ((3, 3), 1, 0, (-1, -1, -1, -1, 8, -1, -1, -1, -1))
name = 'Find Edges'
class PIL.ImageFilter.Filter[source]

Bases: object

class PIL.ImageFilter.GaussianBlur(radius=2)[source]

Bases: PIL.ImageFilter.Filter

filter(image)[source]
name = 'GaussianBlur'
class PIL.ImageFilter.Kernel(size, kernel, scale=None, offset=0)[source]

Bases: PIL.ImageFilter.Filter

filter(image)[source]
class PIL.ImageFilter.MaxFilter(size=3)[source]

Bases: PIL.ImageFilter.RankFilter

name = 'Max'
class PIL.ImageFilter.MedianFilter(size=3)[source]

Bases: PIL.ImageFilter.RankFilter

name = 'Median'
class PIL.ImageFilter.MinFilter(size=3)[source]

Bases: PIL.ImageFilter.RankFilter

name = 'Min'
class PIL.ImageFilter.ModeFilter(size=3)[source]

Bases: PIL.ImageFilter.Filter

filter(image)[source]
name = 'Mode'
class PIL.ImageFilter.RankFilter(size, rank)[source]

Bases: PIL.ImageFilter.Filter

filter(image)[source]
name = 'Rank'
class PIL.ImageFilter.SHARPEN[source]

Bases: PIL.ImageFilter.BuiltinFilter

filterargs = ((3, 3), 16, 0, (-2, -2, -2, -2, 32, -2, -2, -2, -2))
name = 'Sharpen'
class PIL.ImageFilter.SMOOTH[source]

Bases: PIL.ImageFilter.BuiltinFilter

filterargs = ((3, 3), 13, 0, (1, 1, 1, 1, 5, 1, 1, 1, 1))
name = 'Smooth'
class PIL.ImageFilter.SMOOTH_MORE[source]

Bases: PIL.ImageFilter.BuiltinFilter

filterargs = ((5, 5), 100, 0, (1, 1, 1, 1, 1, 1, 5, 5, 5, 1, 1, 5, 44, 5, 1, 1, 5, 5, 5, 1, 1, 1, 1, 1, 1))
name = 'Smooth More'
class PIL.ImageFilter.UnsharpMask(radius=2, percent=150, threshold=3)[source]

Bases: PIL.ImageFilter.Filter

filter(image)[source]
name = 'UnsharpMask'

ImageFont Module

class PIL.ImageFont.FreeTypeFont(font=None, size=10, index=0, encoding='', file=None)[source]

FreeType font wrapper (requires _imagingft service)

getmask(text, mode='')[source]
getmask2(text, mode='', fill=<built-in function fill>)[source]
getmetrics()[source]
getname()[source]
getoffset(text)[source]
getsize(text)[source]
class PIL.ImageFont.ImageFont[source]

PIL font wrapper

class PIL.ImageFont.TransposedFont(font, orientation=None)[source]

Wrapper for writing rotated or mirrored text

getmask(text, mode='')[source]
getsize(text)[source]
PIL.ImageFont.load(filename)[source]

Load a font file.

PIL.ImageFont.load_default()[source]

Load a default font.

PIL.ImageFont.load_path(filename)[source]

Load a font file, searching along the Python path.

PIL.ImageFont.truetype(font=None, size=10, index=0, encoding='', filename=None)[source]

Load a truetype font file.

ImageMath Module

PIL.ImageMath.eval(expression, _dict={}, **kw)[source]
PIL.ImageMath.imagemath_convert(self, mode)[source]
PIL.ImageMath.imagemath_equal(self, other)[source]
PIL.ImageMath.imagemath_float(self)[source]
PIL.ImageMath.imagemath_int(self)[source]
PIL.ImageMath.imagemath_max(self, other)[source]
PIL.ImageMath.imagemath_min(self, other)[source]
PIL.ImageMath.imagemath_notequal(self, other)[source]
PIL.ImageMath.v(self, other)

ImageMode Module

class PIL.ImageMode.ModeDescriptor(mode, bands, basemode, basetype)[source]
PIL.ImageMode.getmode(mode)[source]

ImageOps Module

PIL.ImageOps.autocontrast(image, cutoff=0, ignore=None)[source]

Maximize image contrast, based on histogram

PIL.ImageOps.colorize(image, black, white)[source]

Colorize a grayscale image

PIL.ImageOps.crop(image, border=0)[source]

Crop border off image

PIL.ImageOps.deform(image, deformer, resample=2)[source]

Deform image using the given deformer

PIL.ImageOps.equalize(image, mask=None)[source]

Equalize image histogram

PIL.ImageOps.expand(image, border=0, fill=0)[source]

Add border to image

PIL.ImageOps.fit(image, size, method=0, bleed=0.0, centering=(0.5, 0.5))[source]

This method returns a sized and cropped version of the image, cropped to the aspect ratio and size that you request.

PIL.ImageOps.flip(image)[source]

Flip image vertically

PIL.ImageOps.gaussian_blur(im, radius=None)[source]

PIL_usm.gblur(im, [radius])

PIL.ImageOps.gblur(im[, radius])
PIL.ImageOps.grayscale(image)[source]

Convert to grayscale

PIL.ImageOps.invert(image)[source]

Invert image (negate)

PIL.ImageOps.mirror(image)[source]

Flip image horizontally

PIL.ImageOps.posterize(image, bits)[source]

Reduce the number of bits per color channel

PIL.ImageOps.solarize(image, threshold=128)[source]

Invert all values above threshold

PIL.ImageOps.unsharp_mask(im, radius=None, percent=None, threshold=None)[source]

PIL_usm.usm(im, [radius, percent, threshold])

PIL.ImageOps.usm(im[, radius, percent, threshold])

ImagePalette Module

class PIL.ImagePalette.ImagePalette(mode='RGB', palette=None)[source]

Colour palette for palette mapped images

getcolor(color)[source]
getdata()[source]
save(fp)[source]
tobytes()[source]
tostring()
PIL.ImagePalette.load(filename)[source]
PIL.ImagePalette.negative(mode='RGB')[source]
PIL.ImagePalette.new(mode, data)[source]
PIL.ImagePalette.random(mode='RGB')[source]
PIL.ImagePalette.raw(rawmode, data)[source]
PIL.ImagePalette.sepia(white='#fff0c0')[source]
PIL.ImagePalette.wedge(mode='RGB')[source]

ImagePath Module

ImageQt Module

class PIL.ImageQt.ImageQt(im)[source]

Bases: PyQt4.QtGui.QImage

PIL.ImageQt.rgb(r, g, b)[source]

ImageSequence Module

class PIL.ImageSequence.Iterator(im)[source]

ImageShow Module

class PIL.ImageShow.DisplayViewer[source]

Bases: PIL.ImageShow.UnixViewer

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

Bases: PIL.ImageShow.Viewer

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

Bases: PIL.ImageShow.UnixViewer

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

ImageStat Module

PIL.ImageStat.Global

alias of Stat

class PIL.ImageStat.Stat(image_or_list, mask=None)[source]

Get image or feature statistics

ImageTk Module

class PIL.ImageTk.BitmapImage(image=None, **kw)[source]
height()[source]
width()[source]
class PIL.ImageTk.PhotoImage(image=None, size=None, **kw)[source]
height()[source]
paste(im, box=None)[source]
width()[source]
PIL.ImageTk.getimage(photo)[source]

ImageTransform Module

class PIL.ImageTransform.AffineTransform(data)[source]

Bases: PIL.ImageTransform.Transform

method = 0
class PIL.ImageTransform.ExtentTransform(data)[source]

Bases: PIL.ImageTransform.Transform

method = 1
class PIL.ImageTransform.MeshTransform(data)[source]

Bases: PIL.ImageTransform.Transform

method = 4
class PIL.ImageTransform.QuadTransform(data)[source]

Bases: PIL.ImageTransform.Transform

method = 3
class PIL.ImageTransform.Transform(data)[source]

Bases: PIL.Image.ImageTransformHandler

getdata()[source]
transform(size, image, **options)[source]

ImageWin Module

class PIL.ImageWin.Dib(image, size=None)[source]
draw(handle, dst, src=None)[source]
expose(handle)[source]
frombytes(buffer)[source]
fromstring(*args, **kw)[source]
paste(im, box=None)[source]
query_palette(handle)[source]
tobytes()[source]
tostring()[source]
class PIL.ImageWin.HDC(dc)[source]
class PIL.ImageWin.HWND(wnd)[source]
class PIL.ImageWin.ImageWindow(image, title='PIL')[source]

Bases: PIL.ImageWin.Window

ui_handle_repair(dc, x0, y0, x1, y1)[source]
class PIL.ImageWin.Window(title='PIL', width=None, height=None)[source]
mainloop()[source]
ui_handle_clear(dc, x0, y0, x1, y1)[source]
ui_handle_damage(x0, y0, x1, y1)[source]
ui_handle_destroy()[source]
ui_handle_repair(dc, x0, y0, x1, y1)[source]
ui_handle_resize(width, height)[source]

ImtImagePlugin Module

class PIL.ImtImagePlugin.ImtImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'IMT'
format_description = 'IM Tools'

IptcImagePlugin Module

class PIL.IptcImagePlugin.IptcImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

field()[source]
format = 'IPTC'
format_description = 'IPTC/NAA'
getint(key)[source]
load()[source]
PIL.IptcImagePlugin.dump(c)[source]
PIL.IptcImagePlugin.getiptcinfo(im)[source]
PIL.IptcImagePlugin.i(c)[source]

JpegImagePlugin Module

PIL.JpegImagePlugin.APP(self, marker)[source]
PIL.JpegImagePlugin.COM(self, marker)[source]
PIL.JpegImagePlugin.DQT(self, marker)[source]
class PIL.JpegImagePlugin.JpegImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

draft(mode, size)[source]
format = 'JPEG'
format_description = 'JPEG (ISO 10918)'
load_djpeg()[source]
PIL.JpegImagePlugin.SOF(self, marker)[source]
PIL.JpegImagePlugin.Skip(self, marker)[source]
PIL.JpegImagePlugin.convert_dict_qtables(qtables)[source]
PIL.JpegImagePlugin.get_sampling(im)[source]

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

McIdasImagePlugin Module

class PIL.McIdasImagePlugin.McIdasImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'MCIDAS'
format_description = 'McIdas area file'

MicImagePlugin Module

class PIL.MicImagePlugin.MicImageFile(fp=None, filename=None)[source]

Bases: PIL.TiffImagePlugin.TiffImageFile

format = 'MIC'
format_description = 'Microsoft Image Composer'
seek(frame)[source]
tell()[source]

MpegImagePlugin Module

class PIL.MpegImagePlugin.BitStream(fp)[source]
next()[source]
peek(bits)[source]
read(bits)[source]
skip(bits)[source]
class PIL.MpegImagePlugin.MpegImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'MPEG'
format_description = 'MPEG'

MspImagePlugin Module

class PIL.MspImagePlugin.MspImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'MSP'
format_description = 'Windows Paint'

OleFileIO Module

class PIL.OleFileIO.OleFileIO(filename=None)[source]

OLE container object

This class encapsulates the interface to an OLE 2 structured storage file. Use the listdir and openstream methods to access the contents of this file.

Object names are given as a list of strings, one for each subentry level. The root entry should be omitted. For example, the following code extracts all image streams from a Microsoft Image Composer file:

ole = OleFileIO("fan.mic")

for entry in ole.listdir():
    if entry[1:2] == "Image":
        fin = ole.openstream(entry)
        fout = open(entry[0:1], "wb")
        while 1:
            s = fin.read(8192)
            if not s:
                break
            fout.write(s)

You can use the viewer application provided with the Python Imaging Library to view the resulting files (which happens to be standard TIFF files).

dumpdirectory()[source]
getproperties(filename)[source]

Return properties described in substream

getsect(sect)[source]
listdir()[source]

Return a list of streams stored in this file

loaddirectory(sect)[source]
loadfat(header)[source]
loadminifat()[source]
open(filename)[source]

Open an OLE2 file

openstream(filename)[source]

Open a stream as a read-only file object

PSDraw Module

class PIL.PSDraw.PSDraw(fp=None)[source]
begin_document(id=None)[source]

Write Postscript DSC header

end_document()[source]

Write Postscript DSC footer

image(box, im, dpi=None)[source]

Write an PIL image

line(xy0, xy1)[source]
rectangle(box)[source]
setfont(font, size)[source]
setink(ink)[source]
text(xy, text)[source]

PaletteFile Module

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

PalmImagePlugin Module

PIL.PalmImagePlugin.build_prototype_image()[source]

PcdImagePlugin Module

class PIL.PcdImagePlugin.PcdImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

draft(mode, size)[source]
format = 'PCD'
format_description = 'Kodak PhotoCD'

PcfFontFile Module

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

Bases: PIL.FontFile.FontFile

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

PcxImagePlugin Module

class PIL.PcxImagePlugin.PcxImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'PCX'
format_description = 'Paintbrush'

PdfImagePlugin Module

PixarImagePlugin Module

class PIL.PixarImagePlugin.PixarImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'PIXAR'
format_description = 'PIXAR raster image'

PngImagePlugin Module

class PIL.PngImagePlugin.ChunkStream(fp)[source]
call(cid, pos, len)[source]

Call the appropriate chunk handler

close()[source]
crc(cid, data)[source]

Read and verify checksum

crc_skip(cid, data)[source]

Read checksum. Used if the C module is not present

push(cid, pos, len)[source]
read()[source]

Fetch a new chunk. Returns header information.

verify(endchunk='IEND')[source]
class PIL.PngImagePlugin.PngImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'PNG'
format_description = 'Portable network graphics'
load_end()[source]

internal: finished reading image data

load_prepare()[source]

internal: prepare to read PNG file

load_read(bytes)[source]

internal: read more image data

verify()[source]

Verify PNG file

class PIL.PngImagePlugin.PngInfo[source]
add(cid, data)[source]
add_text(key, value, zip=0)[source]
class PIL.PngImagePlugin.PngStream(fp)[source]

Bases: PIL.PngImagePlugin.ChunkStream

chunk_IDAT(pos, len)[source]
chunk_IEND(pos, len)[source]
chunk_IHDR(pos, len)[source]
chunk_PLTE(pos, len)[source]
chunk_gAMA(pos, len)[source]
chunk_iCCP(pos, len)[source]
chunk_pHYs(pos, len)[source]
chunk_tEXt(pos, len)[source]
chunk_tRNS(pos, len)[source]
chunk_zTXt(pos, len)[source]
PIL.PngImagePlugin.getchunks(im, **params)[source]

Return a list of PNG chunks representing this image.

PIL.PngImagePlugin.is_cid()

match(string[, pos[, endpos]]) –> match object or None. Matches zero or more characters at the beginning of the string

PIL.PngImagePlugin.putchunk(fp, cid, *data)[source]

Write a PNG chunk (including CRC field)

PpmImagePlugin Module

class PIL.PpmImagePlugin.PpmImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'PPM'
format_description = 'Pbmplus image'

PsdImagePlugin Module

class PIL.PsdImagePlugin.PsdImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'PSD'
format_description = 'Adobe Photoshop'
load_prepare()[source]
seek(layer)[source]
tell()[source]

SgiImagePlugin Module

class PIL.SgiImagePlugin.SgiImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'SGI'
format_description = 'SGI Image File Format'

SpiderImagePlugin Module

class PIL.SpiderImagePlugin.SpiderImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

convert2byte(depth=255)[source]
format = 'SPIDER'
format_description = 'Spider 2D image'
seek(frame)[source]
tell()[source]
tkPhotoImage()[source]
PIL.SpiderImagePlugin.isInt(f)[source]
PIL.SpiderImagePlugin.isSpiderHeader(t)[source]
PIL.SpiderImagePlugin.isSpiderImage(filename)[source]
PIL.SpiderImagePlugin.loadImageSeries(filelist=None)[source]

create a list of Image.images for use in montage

PIL.SpiderImagePlugin.makeSpiderHeader(im)[source]

SunImagePlugin Module

class PIL.SunImagePlugin.SunImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'SUN'
format_description = 'Sun Raster File'

TarIO Module

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

Bases: PIL.ContainerIO.ContainerIO

TgaImagePlugin Module

class PIL.TgaImagePlugin.TgaImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'TGA'
format_description = 'Targa'

TiffImagePlugin Module

class PIL.TiffImagePlugin.ImageFileDirectory(prefix)[source]

Bases: _abcoll.MutableMapping

as_dict()[source]

Return a dictionary of the image’s tags.

getscalar(tag, default=None)[source]
has_key(tag)[source]
items()[source]
load(fp)[source]
load_byte(data)[source]
load_dispatch = {1: (1, <function load_byte at 0x2abaeb0>), 2: (1, <function load_string at 0x2abaf30>), 3: (2, <function load_short at 0x2abaf70>), 4: (4, <function load_long at 0x2abafb0>), 5: (8, <function load_rational at 0x2abaab0>), 7: (1, <function load_undefined at 0x2a58070>), 11: (4, <function load_float at 0x2abaa70>), 12: (8, <function load_double at 0x2a58030>)}
load_double(data)[source]
load_float(data)[source]
load_long(data)[source]
load_rational(data)[source]
load_short(data)[source]
load_string(data)[source]
load_undefined(data)[source]
named()[source]

Returns the complete tag dictionary, with named tags where posible.

reset()[source]
save(fp)[source]
class PIL.TiffImagePlugin.TiffImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'TIFF'
format_description = 'Adobe TIFF'
seek(frame)[source]

Select a given frame as current image

tell()[source]

Return the current frame number

TiffTags Module

WalImageFile Module

PIL.WalImageFile.open(filename)[source]

WebPImagePlugin Module

WmfImagePlugin Module

class PIL.WmfImagePlugin.WmfStubImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.StubImageFile

format = 'WMF'
format_description = 'Windows Metafile'
PIL.WmfImagePlugin.register_handler(handler)[source]
PIL.WmfImagePlugin.short(c, o=0)[source]

XVThumbImagePlugin Module

class PIL.XVThumbImagePlugin.XVThumbImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'XVThumb'
format_description = 'XV thumbnail image'

XbmImagePlugin Module

class PIL.XbmImagePlugin.XbmImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'XBM'
format_description = 'X11 Bitmap'

XpmImagePlugin Module

class PIL.XpmImagePlugin.XpmImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'XPM'
format_description = 'X11 Pixel Map'
load_read(bytes)[source]

_binary Module

PIL._binary.i16be(c, o=0)[source]
PIL._binary.i16le(c, o=0)[source]
PIL._binary.i32be(c, o=0)[source]
PIL._binary.i32le(c, o=0)[source]
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]

Table Of Contents

Previous topic

Welcome to Pillow (PIL fork)’s documentation!

This Page