PIL.Image
index
/Library/Python/2.7/site-packages/PIL/Image.py

# The Python Imaging Library.
# $Id$
#
# the Image class wrapper
#
# partial release history:
# 1995-09-09 fl   Created
# 1996-03-11 fl   PIL release 0.0 (proof of concept)
# 1996-04-30 fl   PIL release 0.1b1
# 1999-07-28 fl   PIL release 1.0 final
# 2000-06-07 fl   PIL release 1.1
# 2000-10-20 fl   PIL release 1.1.1
# 2001-05-07 fl   PIL release 1.1.2
# 2002-03-15 fl   PIL release 1.1.3
# 2003-05-10 fl   PIL release 1.1.4
# 2005-03-28 fl   PIL release 1.1.5
# 2006-12-02 fl   PIL release 1.1.6
# 2009-11-15 fl   PIL release 1.1.7
#
# Copyright (c) 1997-2009 by Secret Labs AB.  All rights reserved.
# Copyright (c) 1995-2009 by Fredrik Lundh.
#
# See the README file for information on usage and redistribution.
#

 
Modules
       
PIL.ImageMode
__builtin__
__builtin__
collections
PIL._imaging
io
logging
math
numbers
os
struct
sys
warnings

 
Classes
       
__builtin__.object
Image
ImagePointHandler
ImageTransformHandler
exceptions.RuntimeWarning(exceptions.Warning)
DecompressionBombWarning

 
class DecompressionBombWarning(exceptions.RuntimeWarning)
    
Method resolution order:
DecompressionBombWarning
exceptions.RuntimeWarning
exceptions.Warning
exceptions.Exception
exceptions.BaseException
__builtin__.object

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from exceptions.RuntimeWarning:
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature

Data and other attributes inherited from exceptions.RuntimeWarning:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class Image(__builtin__.object)
    This class represents an image object.  To create
:py:class:`~PIL.Image.Image` objects, use the appropriate factory
functions.  There's hardly ever any reason to call the Image constructor
directly.
 
* :py:func:`~PIL.Image.open`
* :py:func:`~PIL.Image.new`
* :py:func:`~PIL.Image.frombytes`
 
  Methods defined here:
__copy__ = copy(self)
__enter__(self)
# Context Manager Support
__eq__(self, other)
__exit__(self, *args)
__getstate__(self)
__init__(self)
__ne__(self, other)
__repr__(self)
__setstate__(self, state)
close(self)
Closes the file pointer, if possible.
 
This operation will destroy the image core and release its memory.
The image data will be unusable afterward.
 
This function is only required to close images that have not
had their file read and closed by the
:py:meth:`~PIL.Image.Image.load` method.
convert(self, mode=None, matrix=None, dither=None, palette=0, colors=256)
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." The **matrix** argument only supports "L"
and "RGB".
 
When translating a color 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
 
The default method of converting a greyscale ("L") or "RGB"
image into a bilevel (mode "1") image uses Floyd-Steinberg
dither to approximate the original image luminosity levels. If
dither is NONE, all non-zero values are set to 255 (white). To
use other thresholds, use the :py:meth:`~PIL.Image.Image.point`
method.
 
:param mode: The requested mode. See: :ref:`concept-modes`.
:param matrix: An optional conversion matrix.  If given, this
   should be 4- or 12-tuple containing floating point values.
:param dither: Dithering method, used when converting from
   mode "RGB" to "P" or from "RGB" or "L" to "1".
   Available methods are NONE or FLOYDSTEINBERG (default).
:param palette: Palette to use when converting from mode "RGB"
   to "P".  Available palettes are WEB or ADAPTIVE.
:param colors: Number of colors to use for the ADAPTIVE palette.
   Defaults to 256.
:rtype: :py:class:`~PIL.Image.Image`
:returns: An :py:class:`~PIL.Image.Imageobject.
copy(self)
Copies this image. Use this method if you wish to paste things
into an image, but still retain the original.
 
:rtype: :py:class:`~PIL.Image.Image`
:returns: An :py:class:`~PIL.Image.Imageobject.
crop(self, box=None)
Returns a rectangular region from this image. The box is a
4-tuple defining the left, upper, right, and lower pixel
coordinate.
 
Note: Prior to Pillow 3.4.0, this was a lazy operation.
 
:param box: The crop rectangle, as a (left, upper, right, lower)-tuple.
:rtype: :py:class:`~PIL.Image.Image`
:returns: An :py:class:`~PIL.Image.Imageobject.
draft(self, mode, size)
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 color
JPEG to greyscale while loading it, or to extract a 128x192
version from a PCD file.
 
Note that this method modifies the :py:class:`~PIL.Image.Imageobject
in place.  If the image has already been loaded, this method has no
effect.
 
:param mode: The requested mode.
:param size: The requested size.
effect_spread(self, distance)
Randomly spread pixels in an image.
 
:param distance: Distance to spread pixels.
filter(self, filter)
Filters this image using the given filter.  For a list of
available filters, see the :py:mod:`~PIL.ImageFilter` module.
 
:param filter: Filter kernel.
:returns: An :py:class:`~PIL.Image.Imageobject.
frombytes(self, data, decoder_name='raw', *args)
Loads this image with pixel data from a bytes object.
 
This method is similar to the :py:func:`~PIL.Image.frombytes` function,
but loads data into this image instead of creating a new image object.
fromstring(self, *args, **kw)
getbands(self)
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.
:rtype: tuple
getbbox(self)
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(self, maxcolors=256)
Returns a list of colors used in this image.
 
:param 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(self, band=None)
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())**.
 
:param 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(self)
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(self)
Returns a capsule that points to the internal image memory.
 
:returns: A capsule object.
getpalette(self)
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(self, xy)
Returns the pixel value at a given position.
 
:param 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(self)
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(self, mask=None, extrema=None)
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").
 
:param mask: An optional mask.
:returns: A list containing pixel counts.
load(self)
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. This method will close the file
associated with the image.
 
:returns: An image access object.
:rtype: :ref:`PixelAccess` or :py:class:`PIL.PyAccess`
offset(self, xoffset, yoffset=None)
paste(self, im, box=None, mask=None)
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 :py:meth:`~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 color.  When creating RGB images, you can
also use color 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 will mix the two images together, including their alpha
channels if they have them.
 
See :py:meth:`~PIL.Image.Image.alpha_composite` if you want to
combine images with respect to their alpha channels.
 
:param im: Source image or pixel value (integer or tuple).
:param 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.
:param mask: An optional mask image.
point(self, lut, mode=None)
Maps this image through a lookup table or function.
 
:param lut: A lookup table, containing 256 (or 65336 if
   self.mode=="I" and mode == "L") 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.
:param 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" or the
   source image mode is "I" and the output mode is "L".
:returns: An :py:class:`~PIL.Image.Imageobject.
putalpha(self, alpha)
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".
 
:param 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(self, data, scale=1.0, offset=0.0)
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**.
 
:param data: A sequence object.
:param scale: An optional scale value.  The default is 1.0.
:param offset: An optional offset value.  The default is 0.0.
putpalette(self, data, rawmode='RGB')
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.
 
:param data: A palette sequence (either a list or a string).
putpixel(self, xy, value)
Modifies the pixel at the given position. The color 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 :py:meth:`~PIL.Image.Image.paste` or the :py:mod:`~PIL.ImageDraw`
module instead.
 
See:
 
* :py:meth:`~PIL.Image.Image.paste`
* :py:meth:`~PIL.Image.Image.putdata`
* :py:mod:`~PIL.ImageDraw`
 
:param xy: The pixel coordinate, given as (x, y).
:param value: The pixel value.
quantize(self, colors=256, method=None, kmeans=0, palette=None)
Convert the image to 'P' mode with the specified number
of colors.
 
:param colors: The desired number of colors, <= 256
:param method: 0 = median cut
               1 = maximum coverage
               2 = fast octree
               3 = libimagequant
:param kmeans: Integer
:param palette: Quantize to the :py:class:`PIL.ImagingPalette` palette.
:returns: A new image
resize(self, size, resample=0)
Returns a resized copy of this image.
 
:param size: The requested size in pixels, as a 2-tuple:
   (width, height).
:param resample: An optional resampling filter.  This can be
   one of :py:attr:`PIL.Image.NEAREST`, :py:attr:`PIL.Image.BOX`,
   :py:attr:`PIL.Image.BILINEAR`, :py:attr:`PIL.Image.HAMMING`,
   :py:attr:`PIL.Image.BICUBIC` or :py:attr:`PIL.Image.LANCZOS`.
   If omitted, or if the image has mode "1" or "P", it is
   set :py:attr:`PIL.Image.NEAREST`.
   See: :ref:`concept-filters`.
:returns: An :py:class:`~PIL.Image.Imageobject.
rotate(self, angle, resample=0, expand=0, center=None, translate=None)
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.
 
:param angle: In degrees counter clockwise.
:param resample: An optional resampling filter.  This can be
   one of :py:attr:`PIL.Image.NEAREST` (use nearest neighbour),
   :py:attr:`PIL.Image.BILINEAR` (linear interpolation in a 2x2
   environment), or :py:attr:`PIL.Image.BICUBIC`
   (cubic spline interpolation in a 4x4 environment).
   If omitted, or if the image has mode "1" or "P", it is
   set :py:attr:`PIL.Image.NEAREST`. See :ref:`concept-filters`.
:param 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.  Note that the expand flag assumes rotation around
   the center and no translation.
:param center: Optional center of rotation (a 2-tuple).  Origin is
   the upper left corner.  Default is the center of the image.
:param translate: An optional post-rotate translation (a 2-tuple).
:returns: An :py:class:`~PIL.Image.Imageobject.
save(self, fp, format=None, **params)
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 in the
:doc:`image format documentation
<../handbook/image-file-formats>` for each writer.
 
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.
 
:param fp: A filename (string), pathlib.Path object or file object.
:param 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.
:param options: Extra parameters to the image writer.
:returns: None
:exception KeyError: If the output format could not be determined
   from the file name.  Use the format option to solve this.
:exception IOError: If the file could not be written.  The file
   may have been created, and may contain partial data.
seek(self, frame)
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 :py:meth:`~PIL.Image.Image.tell`.
 
:param frame: Frame number, starting at 0.
:exception EOFError: If the call attempts to seek beyond the end
    of the sequence.
show(self, title=None, command=None)
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 either the **xv** utility or the **display**
utility, depending on which one can be found.
 
On macOS, this method saves the image to a temporary BMP file, and opens
it with the native Preview application.
 
On Windows, it saves the image to a temporary BMP file, and uses
the standard BMP display utility to show it (usually Paint).
 
:param title: Optional title to use for the image window,
   where possible.
:param command: command used to show the image
split(self)
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(self)
Returns the current frame number. See :py:meth:`~PIL.Image.Image.seek`.
 
:returns: Frame number, starting with 0.
thumbnail(self, size, resample=3)
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
:py:meth:`~PIL.Image.Image.draft` method to configure the file reader
(where applicable), and finally resizes the image.
 
Note that this function modifies the :py:class:`~PIL.Image.Image`
object in place.  If you need to use the full resolution image as well,
apply this method to a :py:meth:`~PIL.Image.Image.copy` of the original
image.
 
:param size: Requested size.
:param resample: Optional resampling filter.  This can be one
   of :py:attr:`PIL.Image.NEAREST`, :py:attr:`PIL.Image.BILINEAR`,
   :py:attr:`PIL.Image.BICUBIC`, or :py:attr:`PIL.Image.LANCZOS`.
   If omitted, it defaults to :py:attr:`PIL.Image.BICUBIC`.
   (was :py:attr:`PIL.Image.NEAREST` prior to version 2.5.0)
:returns: None
tobitmap(self, name='image')
Returns the image converted to an X11 bitmap.
 
.. note:: This method only works for mode "1" images.
 
:param 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(self, encoder_name='raw', *args)
Return image as a bytes object.
 
.. warning::
 
    This method returns the raw image data from the internal
    storage.  For compressed image data (e.g. PNG, JPEG) use
    :meth:`~.save`, with a BytesIO parameter for in-memory
    data.
 
:param encoder_name: What encoder to use.  The default is to
                     use the standard "raw" encoder.
:param args: Extra arguments to the encoder.
:rtype: A bytes object.
toqimage(self)
Returns a QImage copy of this image
toqpixmap(self)
Returns a QPixmap copy of this image
tostring(self, *args, **kw)
transform(self, size, method, data=None, resample=0, fill=1)
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.
 
:param size: The output size.
:param method: The transformation method.  This is one of
  :py:attr:`PIL.Image.EXTENT` (cut out a rectangular subregion),
  :py:attr:`PIL.Image.AFFINE` (affine transform),
  :py:attr:`PIL.Image.PERSPECTIVE` (perspective transform),
  :py:attr:`PIL.Image.QUAD` (map a quadrilateral to a rectangle), or
  :py:attr:`PIL.Image.MESH` (map a number of source quadrilaterals
  in one operation).
:param data: Extra data to the transformation method.
:param resample: Optional resampling filter.  It can be one of
   :py:attr:`PIL.Image.NEAREST` (use nearest neighbour),
   :py:attr:`PIL.Image.BILINEAR` (linear interpolation in a 2x2
   environment), or :py:attr:`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 :py:attr:`PIL.Image.NEAREST`.
:returns: An :py:class:`~PIL.Image.Imageobject.
transpose(self, method)
Transpose image (flip or rotate in 90 degree steps)
 
:param method: One of :py:attr:`PIL.Image.FLIP_LEFT_RIGHT`,
  :py:attr:`PIL.Image.FLIP_TOP_BOTTOM`, :py:attr:`PIL.Image.ROTATE_90`,
  :py:attr:`PIL.Image.ROTATE_180`, :py:attr:`PIL.Image.ROTATE_270` or
  :py:attr:`PIL.Image.TRANSPOSE`.
:returns: Returns a flipped or rotated copy of this image.
verify(self)
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.

Data descriptors defined here:
__array_interface__
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
height
width

Data and other attributes defined here:
format = None
format_description = None

 
class ImagePointHandler(__builtin__.object)
     Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class ImageTransformHandler(__builtin__.object)
     Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
alpha_composite(im1, im2)
Alpha composite im2 over im1.
 
:param im1: The first image. Must have mode RGBA.
:param im2: The second image.  Must have mode RGBA, and the same size as
   the first image.
:returns: An :py:class:`~PIL.Image.Imageobject.
blend(im1, im2, alpha)
Creates a new image by interpolating between two input images, using
a constant alpha.::
 
    out = image1 * (1.0 - alpha) + image2 * alpha
 
:param im1: The first image.
:param im2: The second image.  Must have the same mode and size as
   the first image.
:param 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 :py:class:`~PIL.Image.Imageobject.
coerce_e(value)
composite(image1, image2, mask)
Create composite image by blending images using a transparency mask.
 
:param image1: The first image.
:param image2: The second image.  Must have the same mode and
   size as the first image.
:param mask: A mask image.  This image can have mode
   "1", "L", or "RGBA", and must have the same size as the
   other two images.
effect_mandelbrot(size, extent, quality)
Generate a Mandelbrot set covering the given extent.
 
:param size: The requested size in pixels, as a 2-tuple:
   (width, height).
:param extent: The extent to cover, as a 4-tuple:
   (x0, y0, x1, y2).
:param quality: Quality.
effect_noise(size, sigma)
Generate Gaussian noise centered around 128.
 
:param size: The requested size in pixels, as a 2-tuple:
   (width, height).
:param sigma: Standard deviation of noise.
eval(image, *args)
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.
 
:param image: The input image.
:param function: A function object, taking one integer argument.
:returns: An :py:class:`~PIL.Image.Imageobject.
fromarray(obj, mode=None)
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 :py:func:`~PIL.Image.frombuffer` is used.
 
:param obj: Object with array interface
:param mode: Mode to use (will be determined from type if None)
  See: :ref:`concept-modes`.
:returns: An image object.
 
.. versionadded:: 1.1.6
frombuffer(mode, size, data, decoder_name='raw', *args)
Creates an image memory referencing pixel data in a byte buffer.
 
This function is similar to :py:func:`~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 :py:func:`~PIL.Image.open` to load it.
 
In the current version, the default parameters used for the "raw" decoder
differs from that used for :py:func:`~PIL.Image.frombytes`.  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.
 
:param mode: The image mode. See: :ref:`concept-modes`.
:param size: The image size.
:param data: A bytes or other buffer object containing raw
    data for the given mode.
:param decoder_name: What decoder to use.
:param 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 :py:class:`~PIL.Image.Imageobject.
 
.. versionadded:: 1.1.4
frombytes(mode, size, data, decoder_name='raw', *args)
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
:ref:`Writing Your Own File Decoder <file-decoders>`.
 
Note that this function decodes pixel data only, not entire images.
If you have an entire image in a string, wrap it in a
:py:class:`~io.BytesIO` object, and use :py:func:`~PIL.Image.open` to load
it.
 
:param mode: The image mode. See: :ref:`concept-modes`.
:param size: The image size.
:param data: A byte buffer containing raw data for the given mode.
:param decoder_name: What decoder to use.
:param args: Additional parameters for the given decoder.
:returns: An :py:class:`~PIL.Image.Imageobject.
fromqimage(im)
Creates an image instance from a QImage image
fromqpixmap(im)
Creates an image instance from a QPixmap image
fromstring(*args, **kw)
getmodebandnames(mode)
Gets a list of individual band names.  Given a mode, this function returns
a tuple containing the names of individual bands (use
:py:method:`~PIL.Image.getmodetype` to get the mode used to store each
individual band.
 
:param 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.
:exception KeyError: If the input mode was not a standard mode.
getmodebands(mode)
Gets the number of individual bands for this mode.
 
:param mode: Input mode.
:returns: The number of bands in this mode.
:exception KeyError: If the input mode was not a standard mode.
getmodebase(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.
 
:param mode: Input mode.
:returns: "L" or "RGB".
:exception KeyError: If the input mode was not a standard mode.
getmodetype(mode)
Gets the storage type mode.  Given a mode, this function returns a
single-layer mode suitable for storing individual bands.
 
:param mode: Input mode.
:returns: "L", "I", or "F".
:exception KeyError: If the input mode was not a standard mode.
init()
Explicitly initializes the Python Imaging Library. This function
loads all available file format drivers.
isImageType(t)
Checks if an object is an image object.
 
.. warning::
 
   This function is for internal use only.
 
:param t: object to check if it's an image
:returns: True if the object is an image
merge(mode, bands)
Merge a set of single band images into a new multiband image.
 
:param mode: The mode to use for the output image. See:
    :ref:`concept-modes`.
:param bands: A sequence containing one single-band image for
    each band in the output image.  All bands must have the
    same size.
:returns: An :py:class:`~PIL.Image.Imageobject.
new(mode, size, color=0)
Creates a new image with the given mode and size.
 
:param mode: The mode to use for the new image. See:
   :ref:`concept-modes`.
:param size: A 2-tuple, containing (width, height) in pixels.
:param color: What color 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 color
   strings as supported by the ImageColor module.  If the color is
   None, the image is not initialised.
:returns: An :py:class:`~PIL.Image.Imageobject.
open(fp, mode='r')
Opens and identifies the given image file.
 
This is a lazy operation; this function identifies the file, but
the file remains open and the actual image data is not read from
the file until you try to process the data (or call the
:py:meth:`~PIL.Image.Image.load` method).  See
:py:func:`~PIL.Image.new`.
 
:param fp: A filename (string), pathlib.Path object or a file object.
   The file object must implement :py:meth:`~file.read`,
   :py:meth:`~file.seek`, and :py:meth:`~file.tell` methods,
   and be opened in binary mode.
:param mode: The mode.  If given, this argument must be "r".
:returns: An :py:class:`~PIL.Image.Imageobject.
:exception IOError: If the file cannot be found, or the image cannot be
   opened and identified.
preinit()
Explicitly load standard file format drivers.
register_extension(id, extension)
Registers an image extension.  This function should not be
used in application code.
 
:param id: An image format identifier.
:param extension: An extension used for this format.
register_mime(id, mimetype)
Registers an image MIME type.  This function should not be used
in application code.
 
:param id: An image format identifier.
:param mimetype: The image MIME type for this format.
register_open(id, factory, accept=None)
Register an image file plugin.  This function should not be used
in application code.
 
:param id: An image format identifier.
:param factory: An image file factory method.
:param accept: An optional function that can be used to quickly
   reject images having another format.
register_save(id, driver)
Registers an image save function.  This function should not be
used in application code.
 
:param id: An image format identifier.
:param driver: A function to save images in this format.
register_save_all(id, driver)
Registers an image function to save all the frames
of a multiframe format.  This function should not be
used in application code.
 
:param id: An image format identifier.
:param driver: A function to save images in this format.

 
Data
        ADAPTIVE = 1
AFFINE = 0
ANTIALIAS = 1
BICUBIC = 3
BILINEAR = 2
BOX = 4
CONTAINER = 2
CUBIC = 3
DEFAULT_STRATEGY = 0
EXTENSION = {}
EXTENT = 1
FASTOCTREE = 2
FILTERED = 1
FIXED = 4
FLIP_LEFT_RIGHT = 0
FLIP_TOP_BOTTOM = 1
FLOYDSTEINBERG = 3
HAMMING = 5
HAS_CFFI = False
HUFFMAN_ONLY = 2
ID = []
LANCZOS = 1
LIBIMAGEQUANT = 3
LINEAR = 2
MAXCOVERAGE = 1
MAX_IMAGE_PIXELS = 89478485
MEDIANCUT = 0
MESH = 4
MIME = {}
MODES = ['1', 'CMYK', 'F', 'HSV', 'I', 'L', 'LAB', 'P', 'RGB', 'RGBA', 'RGBX', 'YCbCr']
NEAREST = 0
NONE = 0
NORMAL = 0
OPEN = {}
ORDERED = 1
PERSPECTIVE = 2
PILLOW_VERSION = '4.0.0'
QUAD = 3
RASTERIZE = 2
RLE = 3
ROTATE_180 = 3
ROTATE_270 = 4
ROTATE_90 = 2
SAVE = {}
SAVE_ALL = {}
SEQUENCE = 1
TRANSPOSE = 5
USE_CFFI_ACCESS = False
VERSION = '1.1.7'
WEB = 0
logger = <logging.Logger object>
print_function = _Feature((2, 6, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 65536)