/usr/share/doc/python-imaging/html/image.htm is in python-imaging-doc-html 1.1.2-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | <html><head><title>The Image Module</title><link rel="stylesheet" type="text/css" href="effbot.css" /></head><body><div id="IMAGE-MODULE" class="chapter"><h1 style="chapter">The Image Module</h1><p>The <tt>Image</tt> module provides a class with
the same name which is used to represent a PIL image. The module also
provides a number of factory functions, including functions to load
images from files, and to create new images.</p><div class="sect1"><h2 style="sect1">Examples</h2><div class="example"><b style="example">Example: Open, rotate, and display an image</b><pre>import Image
im = Image.open("bride.jpg")
im.rotate(45).show()</pre></div><div class="example"><b style="example">Example: Create thumbnails</b><pre>import glob
for infile in glob.glob("*.jpg"):
try:
outfile = os.splitext(file)[0] + ".thumbnail"
Image.open(infile).resize(128, 128).save(outfile, "JPEG")
except:
print "Cannot create thumbnail for %s" % infile</pre></div></div><div class="sect1"><h2 style="sect1">Functions</h2><div id="IMAGE-NEW-FUNCTION" class="sect2"><h3 style="sect2">new</h3><p><tt>new(mode, size [,colour])</tt> ⇒ image</p><blockquote class="blockquote"><p>Creates a new image with the given mode and
size. Size is given as a 2-tuple. The colour is given as a single
numerical value for single-band images, and a tuple for multi-band
images. If the colour is omitted, the image is filled with black. If
the colour is <tt>None</tt>, the image is not
initialised.</p></blockquote></div><div id="IMAGE-OPEN-FUNCTION" class="sect2"><h3 style="sect2">open</h3><p><tt>open(infile [,mode]) ⇒ image</tt>
<blockquote class="blockquote"><p>Opens and identifies the given image file. The
actual image data is not read from the file until you try to process
the data (or call the load method). If the mode argument is given, it
must be <span>"r"</span>.</p><p>You can use either a string (giving the filename) or a file
object. In the latter case, the file object must implement
<tt>read</tt>, <tt>seek</tt>, and
<tt>tell</tt> methods, and be opened in binary
mode.</p></blockquote>
</p></div><div id="IMAGE-BLEND-FUNCTION" class="sect2"><h3 style="sect2">blend</h3><p><tt>blend(image1, image2, alpha) ⇒ image</tt></p><blockquote class="blockquote"><p>Creates a new image by interpolating between the
given images, using a constant alpha. Both images must have the same
size and mode.</p><pre> out = image1 * (1.0 - alpha) + image2 * alpha</pre><p>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.</p></blockquote></div><div id="IMAGE-COMPOSITE-FUNCTION" class="sect2"><h3 style="sect2">composite</h3><p><tt>composite(image1, image2, mask) ⇒
image</tt></p><blockquote class="blockquote"><p>Creates a new image by interpolating between the
given images, using the mask as alpha. The mask can be either
<span>"1"</span>, <span>"L"</span>, or <span>"RGBA"</span>. All
images must have the same size.</p></blockquote></div><div id="IMAGE-EVAL-FUNCTION" class="sect2"><h3 style="sect2">eval</h3><p><tt>eval(function, image) ⇒ image</tt></p><blockquote class="blockquote"><p>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.</p></blockquote></div><div id="IMAGE-FROMSTRING-FUNCTION" class="sect2"><h3 style="sect2">fromstring</h3><p><tt>fromstring(mode, size, data) ⇒ image</tt></p><blockquote class="blockquote"><p>Creates an image memory from pixel data in a string,
using the standard <span>"raw"</span> decoder.</p></blockquote><p><tt>fromstring(mode, size, data, decoder, parameters)
⇒ image</tt></p><blockquote class="blockquote"><p>Same, but allows you to use any pixel decoder
supported by PIL. For more information on available decoders, see the
section <a href="writing-your-own-file-decoder.htm#writing-your-own-file-decoder-appendix"><i>Writing
Your Own File Decoder</i></a>.</p><p>Note that this function decodes pixel data, not entire images.
If you have an entire image in a string, wrap it in a
<tt>StringIO</tt> object, and use <a href="image.htm#image-open-function"><tt>open</tt></a> to load
it.</p></blockquote></div><div id="IMAGE-MERGE-FUNCTION" class="sect2"><h3 style="sect2">merge</h3><p><tt>merge(mode, bands) ⇒ image</tt></p><blockquote class="blockquote"><p>Creates a new image from a number of single band
images. The bands are given as a tuple or list of images, one for each
band described by the mode. All bands must have the same
size.</p></blockquote></div></div><div class="sect1"><h2 style="sect1">Methods</h2><p>An instance of the Image class have the following methods.
Unless otherwise stated, all methods return a new instance of the
<tt>Image</tt> class, holding the resulting image.</p><div id="IMAGE-CONVERT-METHOD" class="sect2"><h3 style="sect2">convert</h3><p><tt>convert(mode) ⇒ image</tt></p><blockquote class="blockquote"><p>Returns a converted copy of an image. For the <span>"P"</span>
mode, this 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.</p><p>The current release supports all possible conversions between
<span>"L"</span>, <span>"RGB"</span> and <span>"CMYK."</span></p><p>When translating a colour image to black and white (mode
<span>"L"</span>), the library uses the ITU-R 601-2 luma
transform:</p><pre> L = R * 299/1000 + G * 587/1000 + B * 114/1000</pre><p>When translating an greyscale image into a bilevel image (mode
<span>"1"</span>), all non-zero values are set to 255 (white). To use
other thresholds, use the <tt>point</tt> method.</p></blockquote><p><tt>convert(mode, matrix) ⇒ image</tt></p><blockquote class="blockquote"><p>Converts an <span>"RGB"</span> image to <span>"L"</span> or
<span>"RGB"</span> using a conversion matrix. The matrix is a 4- or
16-tuple.</p><p>The following example converts an RGB image (linearly calibrated
according to ITU-R 709, using the D65 luminant) to the CIE XYZ colour
space:</p><div class="example"><b style="example">Example: Convert RGB to XYZ</b><pre> rgb2xyz = (
0.412453, 0.357580, 0.180423, 0,
0.212671, 0.715160, 0.072169, 0,
0.019334, 0.119193, 0.950227, 0 )
out = im.convert("RGB", rgb2xyz)</pre></div></blockquote></div><div id="IMAGE-COPY-METHOD" class="sect2"><h3 style="sect2">copy</h3><p><tt>copy() ⇒ image</tt></p><blockquote class="blockquote"><p>Copies the image. Use this method if you wish to paste things
into an image, but still retain the original.</p></blockquote></div><div id="IMAGE-CROP-METHOD" class="sect2"><h3 style="sect2">crop</h3><p><tt>crop(box) ⇒ image</tt></p><blockquote class="blockquote"><p>Returns a rectangular region from the current image. The box is
a 4-tuple defining the left, upper, right, and lower pixel
coordinate.</p></blockquote></div><div id="IMAGE-DRAFT-METHOD" class="sect2"><h3 style="sect2">draft</h3><p><tt>draft(mode, size)</tt></p><blockquote class="blockquote"><p>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.</p></blockquote></div><div id="IMAGE-FILTER-METHOD" class="sect2"><h3 style="sect2">filter</h3><p><tt>filter(filter) ⇒ image</tt></p><blockquote class="blockquote"><p>Returns a copy of an image filtered by the given filter. For a
list of available filters, see the <tt>ImageFilter</tt>
module.</p></blockquote></div><div id="IMAGE-FROMSTRING-METHOD" class="sect2"><h3 style="sect2">fromstring</h3><p><tt>fromstring(data)</tt></p><p><tt>fromstring(data, decoder, parameters)</tt></p><blockquote class="blockquote"><p>Same as the <tt>fromstring</tt> function, but loads
data into the current image.</p></blockquote></div><div id="IMAGE-GETBANDS-METHOD" class="sect2"><h3 style="sect2">getbands</h3><p><tt>getbands() ⇒ tuple of strings</tt></p><blockquote class="blockquote"><p>Returns a tuple containing the name of each band.
For example, <tt>getbands</tt> on an RGB image returns
(<span>"R"</span>, <span>"G"</span>,
<span>"B"</span>).</p></blockquote></div><div id="IMAGE-GETBBOX-METHOD" class="sect2"><h3 style="sect2">getbbox</h3><p><tt>getbbox() ⇒ tuple</tt></p><blockquote class="blockquote"><p>Calculates the bounding box of the non-zero regions in the
image. 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 <tt>None</tt>.</p></blockquote></div><div id="IMAGE-GETDATA-METHOD" class="sect2"><h3 style="sect2">getdata</h3><p><tt>getdata() ⇒ sequence</tt></p><blockquote class="blockquote"><p>Returns the contents of a the image as a sequence object
containing pixel values. The sequence object is flattened, so that
values for line one follows directly after the values for line zero,
and so on.</p></blockquote></div><div id="IMAGE-GETEXTREMA-METHOD" class="sect2"><h3 style="sect2">getextrema</h3><p><tt>getextrema() ⇒ sequence</tt></p><blockquote class="blockquote"><p>Returns a 2-tuple containing the minimum and maximum values in
the image. In this version, this only works for single-band
images.</p></blockquote></div><div id="IMAGE-GETPIXEL-METHOD" class="sect2"><h3 style="sect2">getpixel</h3><p><tt>getpixel(xy) ⇒ value or tuple</tt></p><blockquote class="blockquote"><p>Returns the pixel at the given position. If the image is a
multi-layer image, this method returns a tuple.</p></blockquote></div><div id="IMAGE-HISTOGRAM-METHOD" class="sect2"><h3 style="sect2">histogram</h3><p><tt>histogram() ⇒ list</tt></p><blockquote class="blockquote"><p>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
<span>"RGB"</span> image contains 768 values).</p><p>A bilevel image (mode <span>"1"</span>) is treated as an
greyscale (<span>"L"</span>) image by this method.</p></blockquote><p><tt>histogram(mask) ⇒ list</tt></p><blockquote class="blockquote"><p>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 <span>"1"</span>) or a
greyscale image (<span>"L"</span>).</p></blockquote></div><div id="IMAGE-LOAD-METHOD" class="sect2"><h3 style="sect2">load</h3><p><tt>load()</tt></p><blockquote class="blockquote"><p>Allocates storage for the image and loads it from the file. In
normal cases, you don't need to call this method, since the Image
class automatically loads an opened image when it is accessed the
first time.</p></blockquote></div><div id="IMAGE-OFFSET-METHOD" class="sect2"><h3 style="sect2">offset</h3><p>(Deprecated). <tt>offset(xoffset,
yoffset) ⇒ image</tt></p><blockquote class="blockquote"><p>Returns a copy of the image where data have been offset by the
given distances. Data wraps around the edges. If yoffset is omitted,
it is assumed to be equal to xoffset.</p><p>This method is deprecated. New code should use the
<tt>offset</tt> function in the <a href="imagechops.htm#imagechops-module"><tt>ImageChops</tt></a>
module.</p></blockquote></div><div id="IMAGE-PASTE-METHOD" class="sect2"><h3 style="sect2">paste</h3><p><tt>paste(image, box)</tt></p><blockquote class="blockquote"><p>Pastes an image into self. The box argument is either a 2-tuple
giving the upper left corner, or a 4-tuple defining the left, upper,
right, and lower pixel coordinate. If <tt>None</tt> is
given instead of a tuple, all of self is assumed. In any case, the
size of the pasted image must match the size of the region.</p><p>If the mode does not match the mode of self, conversions are
automatically applied (see the convert method for details).</p></blockquote><p><tt>paste(colour, box)</tt></p><blockquote class="blockquote"><p>Same as above, but fills the region with a single colour. The
colour is given as a single numerical value for single-band images,
and a tuple for multi-band images.</p><p><tt>paste(image, box, mask)</tt></p><p>Same as above, but updates only the regions indicated by the
mask. You can use either <span>"1"</span>, <span>"L"</span> or
<span>"RGBA"</span> 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.</p><p>Note that if you paste an <span>"RGBA"</span> image, the alpha
band is ignored unless you use the same image as mask.</p></blockquote><p><tt>paste(colour, box, mask)</tt></p><blockquote class="blockquote"><p>Same as above, but fills the region with a single colour.</p></blockquote></div><div id="IMAGE-POINT-METHOD" class="sect2"><h3 style="sect2">point</h3><p><tt>point(table) ⇒ image</tt></p><p><tt>point(function) ⇒ image</tt></p><blockquote class="blockquote"><p>Returns a copy of the image where each pixel has been mapped
through the given table. The table should contains 256 values per band
in the image. If a function is 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.</p><p>If the image has mode <span>"I"</span> (integer) or
<span>"F"</span> (floating point), you must use a function, and it
must have the following format:</p><pre> argument * scale + offset</pre><div class="example"><b style="example">Example: Map floating point images</b><pre> out = im.point(lambda i: i * 1.2 + 10)</pre></div><p>You can leave out either the <tt>scale</tt> or the
<tt>offset</tt>.</p></blockquote><p><tt>point(table, mode) ⇒ image</tt></p><p><tt>point(function, mode) ⇒ image</tt></p><blockquote class="blockquote"><p>Map the image through table, and convert it on fly. In this
version, this can only be used to convert <span>"L"</span> and
<span>"P"</span> images to <span>"1"</span> in one step, e.g. to
threshold an image.</p></blockquote></div><div id="IMAGE-PUTALPHA-METHOD" class="sect2"><h3 style="sect2">putalpha</h3><p><tt>putalpha(band)</tt></p><blockquote class="blockquote"><p>Copies the given band to the alpha layer of self. Self must be
an <span>"RGBA"</span> image, and the band must be either
<span>"L"</span> or <span>"1"</span>.</p></blockquote></div><div id="IMAGE-PUTDATA-METHOD" class="sect2"><h3 style="sect2">putdata</h3><p><tt>putdata(data [[,scale [,offset]])</tt></p><blockquote class="blockquote"><p>Copy pixel values from a sequence object into the image,
starting at the upper left corner. The scale and offset values are
used to adjust the sequence values. If the scale is omitted, it
defaults to 1.0. If the offset is omitted, it defaults to 0.0.</p></blockquote></div><div id="IMAGE-PUTPALETTE-METHOD" class="sect2"><h3 style="sect2">putpalette</h3><p><tt>putpalette(sequence)</tt></p><blockquote class="blockquote"><p>Attach a palette to a <span>"P"</span> or <span>"L"</span>
image. The palette sequence should 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.</p></blockquote></div><div id="IMAGE-PUTPIXEL-METHOD" class="sect2"><h3 style="sect2">putpixel</h3><p><tt>putpixel(xy, colour)</tt></p><blockquote class="blockquote"><p>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.</p><p>For more extensive changes, use <tt>paste</tt> or
the <tt>ImageDraw</tt> module instead.</p></blockquote></div><div id="IMAGE-RESIZE-METHOD" class="sect2"><h3 style="sect2">resize</h3><p><tt>resize(size) ⇒ image</tt></p><p><tt>resize(size, filter) ⇒ image</tt></p><blockquote class="blockquote"><p>Returns a resized copy of an image. The size argument gives the
requested size in pixels, as a 2-tuple: (<tt>width</tt>,
<tt>height</tt>).</p><p>The filter argument can be <tt>NEAREST</tt>,
<tt>BILINEAR</tt>, or <tt>BICUBIC</tt>. If
omitted, it defaults to <tt>NEAREST</tt>.</p></blockquote></div><div id="IMAGE-ROTATE-METHOD" class="sect2"><h3 style="sect2">rotate</h3><p><tt>rotate(angle) ⇒ image</tt></p><p><tt>rotate(angle, filter)</tt></p><blockquote class="blockquote"><p>Returns a copy of an image rotated the given number of degrees
counter clockwise around its centre.</p><p>The filter argument can be <tt>NEAREST</tt>,
<tt>BILINEAR</tt>, or <tt>BICUBIC</tt>. If
omitted, it defaults to <tt>NEAREST</tt>.</p></blockquote></div><div id="IMAGE-SAVE-METHOD" class="sect2"><h3 style="sect2">save</h3><p><tt>save(outfile, options)</tt></p><p><tt>save(outfile, format, options)</tt></p><blockquote class="blockquote"><p>Saves the image under the given filename. If format is omitted,
the format is determined from the filename extension, if
possible. This method returns <tt>None</tt>.</p><p>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.</p><p>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
<tt>seek</tt>, <tt>tell</tt>, and
<tt>write</tt> methods, and be opened in binary
mode.</p></blockquote></div><div id="IMAGE-SEEK-METHOD" class="sect2"><h3 style="sect2">seek</h3><p><tt>seek(frame)</tt></p><blockquote class="blockquote"><p>Seeks to the given frame in a sequence file. If you seek beyond
the end of the sequence, the method raises an
<tt>EOFError</tt> exception. When a sequence file is
opened, the library automatically seeks to frame 0.</p><p>Note that in the current version of the library, most sequence
formats only allows you to seek to the next frame.</p></blockquote></div><div id="IMAGE-SHOW-METHOD" class="sect2"><h3 style="sect2">show</h3><p><tt>show()</tt></p><blockquote class="blockquote"><p>Displays an image. This method is mainly intended for debugging
purposes.</p><p>On Unix platforms, this method saves the image to a temporary
PPM file, and calls the <tt>xv</tt> utility.</p><p>On Windows, it saves the image to a temporary BMP file, and runs
the <tt>start</tt> command on it to start the registered
BMP display utility (usually <tt>Paint</tt>).</p><p>This method returns <tt>None</tt>.</p></blockquote></div><div id="IMAGE-SPLIT-METHOD" class="sect2"><h3 style="sect2">split</h3><p><tt>split() ⇒ sequence</tt></p><blockquote class="blockquote"><p>Returns a tuple of individual image bands from an image. For
example, if you split an <span>"RGB"</span> image, you get three new
images, containing copies of the red, green, and blue bands from the
original image.</p></blockquote></div><div id="IMAGE-TELL-METHOD" class="sect2"><h3 style="sect2">tell</h3><p><tt>tell() ⇒ integer</tt></p><blockquote class="blockquote"><p>Returns the current frame number.</p></blockquote></div><div id="IMAGE-THUMBNAIL-METHOD" class="sect2"><h3 style="sect2">thumbnail</h3><p><tt>thumbnail(size)</tt></p><blockquote class="blockquote"><p>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
<tt>draft</tt> method to configure the file reader (where
applicable), and finally resizes the image.</p><p>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 <tt>copy</tt> of the original image. This method
returns <tt>None</tt>.</p></blockquote></div><div id="IMAGE-TOBITMAP-METHOD" class="sect2"><h3 style="sect2">tobitmap</h3><p><tt>tobitmap() ⇒ string</tt></p><blockquote class="blockquote"><p>Returns the image converted to an X11 bitmap.</p></blockquote></div><div id="IMAGE-TOSTRING-METHOD" class="sect2"><h3 style="sect2">tostring</h3><p><tt>tostring()</tt></p><blockquote class="blockquote"><p>Returns a string containing pixel data, using the standard
<span>"raw"</span> encoder.</p></blockquote><p><tt>tostring(decoder, parameters)</tt></p><blockquote class="blockquote"><p /></blockquote></div><div id="IMAGE-TRANSFORM-METHOD" class="sect2"><h3 style="sect2">transform</h3><p><tt>transform(size, method, data) ⇒ image</tt></p><p><tt>transform(size, method, data, filter) ⇒
image</tt></p><blockquote class="blockquote"><p>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.</p><p>In this version, the <i>method</i> argument can be
<tt>EXTENT</tt> (cut out a rectangular subregion),
<tt>AFFINE</tt> (affine transform),
<tt>QUAD</tt> (map a quadrilateral to a rectangle), or
<tt>MESH</tt> (map a number of source quadrilaterals in
one operation). The various methods are described below.</p><p>The filter argument defines how to filter pixels from the source
image. In this version, it can be <tt>NEAREST</tt> (use
nearest neighbour), <tt>BILINEAR</tt> (linear
interpolatation in a 2x2 environment), or <tt>BICUBIC</tt>
(cubic spline interpolation in a 4x4 environment). If omitted, it
defaults to <tt>NEAREST</tt>.</p></blockquote></div><div class="sect2"><h3 style="sect2">transform(EXTENT)</h3><p><tt>transform(size, EXTENT, data) ⇒
image</tt></p><p><tt>transform(size, EXTENT, data, filter) ⇒
image</tt></p><blockquote class="blockquote"><p>Extracts a subregion from the image.</p><p><i>Data</i> is a 4-tuple (<i>x0, y0, x1,
y1</i>) which specifies two points in the input image's
coordinate system. The resulting image will contain data sampled from
between these two points, so that (<i>x0, y0</i>) in the
input image will end up at (0,0) in the output image, and
(<i>x1, y1</i>) at <i>size</i>.</p><p>This method can be used to crop, stretch, shrink, or mirror an
arbitrary rectangle in the current image. It is slightly slower than
<tt>crop</tt>, but about as fast as a corresponding
<tt>resize</tt> operation.</p></blockquote></div><div class="sect2"><h3 style="sect2">transform(AFFINE)</h3><p><tt>transform(size, AFFINE, data) ⇒ image</tt></p><p><tt>transform(size, AFFINE, data, filter) ⇒
image</tt></p><blockquote class="blockquote"><p>Applies an affine transform to the image, and places the result
in a new image with the given size.</p><p><i>Data</i> is a 6-tuple (<i>a, b, c, d, e,
f</i>) which contain the first two rows from an affine
transform matrix. For each pixel (<i>x, y</i>) in the
output image, the new value is taken from a position (a
<i>x</i> + b <i>y</i> + c, d
<i>x</i> + e <i>y</i> + f) in the input
image, rounded to nearest pixel.</p><p>This function can be used to scale, translate, rotate, and shear
the original image.</p></blockquote></div><div class="sect2"><h3 style="sect2">transform(QUAD)</h3><p><tt>transform(size, QUAD, data) ⇒ image</tt></p><p><tt>transform(size, QUAD, data, filter) ⇒
image</tt></p><blockquote class="blockquote"><p>Maps a quadrilateral (a region defined by four corners) from the
image to a rectangle with the given size.</p><p><i>Data</i> is an 8-tuple (<i>x0, y0, x1,
y1, x2, y2, y3, y3</i>) which contain the upper left, lower
left, lower right, and upper right corner of the source
quadrilateral.</p></blockquote></div><div class="sect2"><h3 style="sect2">transform(MESH)</h3><p><tt>transform(size, MESH, data) ⇒
image</tt></p><p><tt>transform(size, MESH, data, filter) ⇒
image</tt></p><blockquote class="blockquote"><p>Similar to <tt>QUAD</tt>, but data is a list of target
rectangles and corresponding source quadrilaterals.</p></blockquote></div><div id="IMAGE-TRANSPOSE-METHOD" class="sect2"><h3 style="sect2">transpose</h3><p><tt>transpose(method) ⇒ image</tt></p><blockquote class="blockquote"><p>Returns a flipped or rotated copy of an image.</p><p><i>Method</i> can be one of the following:
<tt>FLIP_LEFT_RIGHT</tt>,
<tt>FLIP_TOP_BOTTOM</tt>, <tt>ROTATE_90</tt>,
<tt>ROTATE_180</tt>, or <tt>ROTATE_270</tt>.</p></blockquote></div><div id="IMAGE-VERIFY-METHOD" class="sect2"><h3 style="sect2">verify</h3><p><tt>verify()</tt></p><blockquote class="blockquote"><p>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.</p></blockquote></div></div><div class="sect1"><h2 style="sect1">Attributes</h2><p>Instances of the <tt>Image</tt> class have the
following attributes:</p><div id="IMAGE-FORMAT-ATTRIBUTE" class="sect2"><h3 style="sect2">format</h3><p><tt>format</tt> (string or <tt>None</tt>)</p><blockquote class="blockquote"><p>The file format that this image was read from. For images
created by the library, this attribute is set to
<tt>None</tt>.</p></blockquote></div><div id="IMAGE-MODE-ATTRIBUTE" class="sect2"><h3 style="sect2">mode</h3><p><tt>mode</tt> (string)</p><blockquote class="blockquote"><p>Image mode. This is a string specifying the pixel format used by
the image, with typical values like <span>"1"</span>,
<span>"L"</span>, <span>"RGB"</span>, or <span>"CMYK."</span></p></blockquote></div><div id="IMAGE-SIZE-ATTRIBUTE" class="sect2"><h3 style="sect2">size</h3><p><tt>size</tt> (tuple of integers)</p><blockquote class="blockquote"><p>Image size, in pixels. The size is given as a 2-tuple, with the
width given first.</p></blockquote></div><div id="IMAGE-PALETTE-ATTRIBUTE" class="sect2"><h3 style="sect2">palette</h3><p><tt>palette</tt></p><blockquote class="blockquote"><p>Colour palette table, if any. If mode is <span>"P"</span>, this
should be an instance of the <tt>ImagePalette</tt>
class. Otherwise, it should be set to
<tt>None</tt>.</p></blockquote></div><div id="IMAGE-INFO-ATTRIBUTE" class="sect2"><h3 style="sect2">info</h3><p><tt>info</tt> (dictionary)</p><blockquote class="blockquote"><p>A dictionary holding data associated with the image.</p></blockquote></div></div></div></body></html>
|