Bases: PIL.ImageFile.ImageFile
Bases: PIL.PngImagePlugin.ChunkStream
Parser callbacks for ARG data
Bases: PIL.FontFile.FontFile
Bases: PIL.ImageFile.ImageFile
Bases: PIL.BmpImagePlugin.BmpImageFile
Bases: PIL.ImageFile.StubImageFile
Bases: PIL.BmpImagePlugin.BmpImageFile
Bases: PIL.ImageFile.ImageFile
EPS File Parser for the Python Imaging Library
Bases: PIL.ImageFile.StubImageFile
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.StubImageFile
Bases: PIL.ImageFile.StubImageFile
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.
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
Bases: PIL.ImageFile.ImageFile
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.
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: |
|
---|---|
Return type: | |
Returns: | An Image object. |
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. |
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. |
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: |
|
---|
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. |
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.
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 |
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. |
---|
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. |
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. |
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. |
---|
Returns a capsule that points to the internal image memory.
Returns: | A capsule object. |
---|
Returns the image palette as a list.
Returns: | A list of color values [r, g, b, ...], or None if the image has no palette. |
---|
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. |
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. |
---|
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. |
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. |
---|
(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: |
|
---|---|
Returns: | An Image object. |
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: |
|
---|---|
Returns: | An Image object. |
Maps this image through a lookup table or function.
Parameters: |
|
---|---|
Returns: | An Image object. |
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. |
---|
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: |
|
---|
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). |
---|
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: |
|
---|
Returns a resized copy of this image.
Parameters: |
|
---|---|
Returns: | An Image object. |
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: |
|
---|---|
Returns: | An Image object. |
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: |
|
---|---|
Returns: | None |
Raises: |
|
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.
Parameters: | frame – Frame number, starting at 0. |
---|---|
Raises EOFError: | |
If the call attempts to seek beyond the end of the sequence. |
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: |
|
---|
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. |
---|
Returns the current frame number. See PIL.Image.Image.seek().
Returns: | Frame number, starting with 0. |
---|
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: |
|
---|---|
Returns: | None |
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” |
Return image as a bytes object
Parameters: |
|
---|---|
Return type: | A bytes object. |
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: |
|
---|---|
Returns: | An Image object. |
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. |
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.
Alpha composite im2 over im1.
Parameters: |
|
---|---|
Returns: | An Image object. |
Creates a new image by interpolating between two input images, using a constant alpha.:
out = image1 * (1.0 - alpha) + image2 * alpha
Parameters: |
|
---|---|
Returns: | An Image object. |
Create composite image by blending images using a transparency mask.
Parameters: |
|
---|
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: |
|
---|---|
Returns: | An Image object. |
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: |
|
---|---|
Returns: | An image memory. |
New in version 1.1.6.
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: |
|
---|---|
Returns: | An Image object. |
New in version 1.1.4.
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: |
|
---|---|
Returns: | An Image object. |
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. |
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. |
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. |
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. |
Explicitly initializes the Python Imaging Library. This function loads all available file format drivers.
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 |
Merge a set of single band images into a new multiband image.
Parameters: |
|
---|---|
Returns: | An Image object. |
Creates a new image with the given mode and size.
Parameters: |
|
---|---|
Returns: | An Image object. |
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: |
|
---|---|
Returns: | An Image object. |
Raises IOError: | If the file cannot be found, or the image cannot be opened and identified. |
Registers an image extension. This function should not be used in application code.
Parameters: |
|
---|
Registers an image MIME type. This function should not be used in application code.
Parameters: |
|
---|
Register an image file plugin. This function should not be used in application code.
Parameters: |
|
---|
Blend two images using a constant transparency weight
Create composite image by blending images using a transparency mask
Bases: PIL.Image.ImagePointHandler
Bases: PIL.ImageEnhance._Enhance
Adjust image brightness
Bases: PIL.ImageEnhance._Enhance
Adjust image colour balance
Bases: PIL.Image.Image
Base class for image file format handlers.
Incremental image parser. This class implements the standard feed/close consumer interface.
(Consumer) Close the stream.
Returns: | An image object. |
---|---|
Raises IOError: | If the parser failed to parse the image file. |
(Consumer) Feed data to the parser.
:param data” A string buffer. :exception IOError: If the parser failed to parse the image file.
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.
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
Bases: PIL.ImageFilter.BuiltinFilter
Bases: PIL.ImageFilter.Kernel
Bases: PIL.ImageFilter.BuiltinFilter
Bases: PIL.ImageFilter.BuiltinFilter
Bases: PIL.ImageFilter.BuiltinFilter
Bases: PIL.ImageFilter.BuiltinFilter
Bases: PIL.ImageFilter.BuiltinFilter
Bases: PIL.ImageFilter.BuiltinFilter
Bases: PIL.ImageFilter.Filter
Bases: PIL.ImageFilter.Filter
Bases: PIL.ImageFilter.RankFilter
Bases: PIL.ImageFilter.RankFilter
Bases: PIL.ImageFilter.RankFilter
Bases: PIL.ImageFilter.Filter
Bases: PIL.ImageFilter.Filter
Bases: PIL.ImageFilter.BuiltinFilter
Bases: PIL.ImageFilter.BuiltinFilter
Bases: PIL.ImageFilter.BuiltinFilter
FreeType font wrapper (requires _imagingft service)
Maximize image contrast, based on histogram
This method returns a sized and cropped version of the image, cropped to the aspect ratio and size that you request.
PIL_usm.usm(im, [radius, percent, threshold])
Bases: PIL.ImageShow.UnixViewer
Bases: PIL.ImageShow.Viewer
Bases: PIL.ImageShow.UnixViewer
Bases: PIL.ImageTransform.Transform
Bases: PIL.ImageTransform.Transform
Bases: PIL.ImageTransform.Transform
Bases: PIL.ImageTransform.Transform
Bases: PIL.ImageWin.Window
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.ImageFile
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 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.
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:
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
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.ImageFile
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).
Bases: PIL.FontFile.FontFile
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.ImageFile
Return a list of PNG chunks representing this image.
match(string[, pos[, endpos]]) –> match object or None. Matches zero or more characters at the beginning of the string
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ContainerIO.ContainerIO
Bases: PIL.ImageFile.ImageFile
Bases: _abcoll.MutableMapping
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.StubImageFile
Bases: PIL.ImageFile.ImageFile
Bases: PIL.ImageFile.ImageFile