2013-10-12 09:18:28 +04:00
|
|
|
|
.. py:module:: PIL.Image
|
|
|
|
|
.. py:currentmodule:: PIL.Image
|
|
|
|
|
|
2020-06-22 06:52:50 +03:00
|
|
|
|
:py:mod:`~PIL.Image` Module
|
|
|
|
|
===========================
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
|
|
|
|
The :py:mod:`~PIL.Image` 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.
|
|
|
|
|
|
|
|
|
|
Examples
|
|
|
|
|
--------
|
|
|
|
|
|
2018-02-28 15:50:02 +03:00
|
|
|
|
Open, rotate, and display an image (using the default viewer)
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
2013-10-12 09:18:28 +04:00
|
|
|
|
The following script loads an image, rotates it 45 degrees, and displays it
|
2019-06-24 11:04:13 +03:00
|
|
|
|
using an external viewer (usually xv on Unix, and the Paint program on
|
2023-02-24 00:17:10 +03:00
|
|
|
|
Windows). ::
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
|
|
|
|
from PIL import Image
|
2021-02-25 15:41:31 +03:00
|
|
|
|
with Image.open("hopper.jpg") as im:
|
|
|
|
|
im.rotate(45).show()
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
|
|
|
|
Create thumbnails
|
|
|
|
|
^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
2018-02-28 15:50:02 +03:00
|
|
|
|
The following script creates nice thumbnails of all JPEG images in the
|
2023-02-24 00:17:10 +03:00
|
|
|
|
current directory preserving aspect ratios with 128x128 max resolution. ::
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
import glob, os
|
|
|
|
|
|
|
|
|
|
size = 128, 128
|
|
|
|
|
|
|
|
|
|
for infile in glob.glob("*.jpg"):
|
|
|
|
|
file, ext = os.path.splitext(infile)
|
2021-02-25 15:41:31 +03:00
|
|
|
|
with Image.open(infile) as im:
|
|
|
|
|
im.thumbnail(size)
|
|
|
|
|
im.save(file + ".thumbnail", "JPEG")
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
|
|
|
|
Functions
|
|
|
|
|
---------
|
|
|
|
|
|
|
|
|
|
.. autofunction:: open
|
|
|
|
|
|
2015-02-10 21:15:47 +03:00
|
|
|
|
.. warning::
|
|
|
|
|
To protect against potential DOS attacks caused by "`decompression bombs`_" (i.e. malicious files
|
|
|
|
|
which decompress into a huge amount of data and are designed to crash or cause disruption by using up
|
2020-07-21 13:46:50 +03:00
|
|
|
|
a lot of memory), Pillow will issue a ``DecompressionBombWarning`` if the number of pixels in an
|
2022-09-03 13:53:22 +03:00
|
|
|
|
image is over a certain limit, :py:data:`MAX_IMAGE_PIXELS`.
|
2020-07-21 16:01:51 +03:00
|
|
|
|
|
2022-09-03 13:53:22 +03:00
|
|
|
|
This threshold can be changed by setting :py:data:`MAX_IMAGE_PIXELS`. It can be disabled
|
2020-07-21 16:01:51 +03:00
|
|
|
|
by setting ``Image.MAX_IMAGE_PIXELS = None``.
|
|
|
|
|
|
|
|
|
|
If desired, the warning can be turned into an error with
|
|
|
|
|
``warnings.simplefilter('error', Image.DecompressionBombWarning)`` or suppressed entirely with
|
|
|
|
|
``warnings.simplefilter('ignore', Image.DecompressionBombWarning)``. See also
|
|
|
|
|
`the logging documentation`_ to have warnings output to the logging facility instead of stderr.
|
|
|
|
|
|
2022-09-03 13:53:22 +03:00
|
|
|
|
If the number of pixels is greater than twice :py:data:`MAX_IMAGE_PIXELS`, then a
|
2020-07-21 14:46:31 +03:00
|
|
|
|
``DecompressionBombError`` will be raised instead.
|
2014-07-15 09:25:02 +04:00
|
|
|
|
|
2020-05-01 21:23:39 +03:00
|
|
|
|
.. _decompression bombs: https://en.wikipedia.org/wiki/Zip_bomb
|
|
|
|
|
.. _the logging documentation: https://docs.python.org/3/library/logging.html#integration-with-the-warnings-module
|
2014-06-27 22:30:08 +04:00
|
|
|
|
|
2013-10-12 09:18:28 +04:00
|
|
|
|
Image processing
|
|
|
|
|
^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
.. autofunction:: alpha_composite
|
|
|
|
|
.. autofunction:: blend
|
|
|
|
|
.. autofunction:: composite
|
|
|
|
|
.. autofunction:: eval
|
|
|
|
|
.. autofunction:: merge
|
|
|
|
|
|
|
|
|
|
Constructing images
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
.. autofunction:: new
|
|
|
|
|
.. autofunction:: fromarray
|
|
|
|
|
.. autofunction:: frombytes
|
|
|
|
|
.. autofunction:: frombuffer
|
|
|
|
|
|
2020-06-22 11:55:54 +03:00
|
|
|
|
Generating images
|
|
|
|
|
^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
.. autofunction:: effect_mandelbrot
|
|
|
|
|
.. autofunction:: effect_noise
|
|
|
|
|
.. autofunction:: linear_gradient
|
|
|
|
|
.. autofunction:: radial_gradient
|
|
|
|
|
|
2013-10-12 09:18:28 +04:00
|
|
|
|
Registering plugins
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
2023-09-16 02:06:23 +03:00
|
|
|
|
.. autofunction:: preinit
|
|
|
|
|
.. autofunction:: init
|
|
|
|
|
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. note::
|
|
|
|
|
|
2023-09-16 02:06:23 +03:00
|
|
|
|
These functions are for use by plugin authors. They are called when a
|
|
|
|
|
plugin is loaded as part of :py:meth:`~preinit()` or :py:meth:`~init()`.
|
|
|
|
|
Application authors can ignore them.
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
|
|
|
|
.. autofunction:: register_open
|
|
|
|
|
.. autofunction:: register_mime
|
|
|
|
|
.. autofunction:: register_save
|
2020-06-22 11:55:54 +03:00
|
|
|
|
.. autofunction:: register_save_all
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. autofunction:: register_extension
|
2020-06-22 11:55:54 +03:00
|
|
|
|
.. autofunction:: register_extensions
|
|
|
|
|
.. autofunction:: registered_extensions
|
|
|
|
|
.. autofunction:: register_decoder
|
|
|
|
|
.. autofunction:: register_encoder
|
2017-04-03 23:21:50 +03:00
|
|
|
|
|
2013-10-12 09:18:28 +04:00
|
|
|
|
The Image Class
|
|
|
|
|
---------------
|
|
|
|
|
|
|
|
|
|
.. autoclass:: PIL.Image.Image
|
|
|
|
|
|
|
|
|
|
An instance of the :py:class:`~PIL.Image.Image` class has the following
|
|
|
|
|
methods. Unless otherwise stated, all methods return a new instance of the
|
|
|
|
|
:py:class:`~PIL.Image.Image` class, holding the resulting image.
|
|
|
|
|
|
2017-06-29 15:14:43 +03:00
|
|
|
|
|
|
|
|
|
.. automethod:: PIL.Image.Image.alpha_composite
|
2022-06-11 15:31:07 +03:00
|
|
|
|
.. automethod:: PIL.Image.Image.apply_transparency
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.convert
|
|
|
|
|
|
|
|
|
|
The following example converts an RGB image (linearly calibrated according to
|
2023-02-18 12:34:52 +03:00
|
|
|
|
ITU-R 709, using the D65 luminant) to the CIE XYZ color space::
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
|
|
|
|
rgb2xyz = (
|
|
|
|
|
0.412453, 0.357580, 0.180423, 0,
|
|
|
|
|
0.212671, 0.715160, 0.072169, 0,
|
2019-06-24 11:04:13 +03:00
|
|
|
|
0.019334, 0.119193, 0.950227, 0)
|
2013-10-12 09:18:28 +04:00
|
|
|
|
out = im.convert("RGB", rgb2xyz)
|
|
|
|
|
|
|
|
|
|
.. automethod:: PIL.Image.Image.copy
|
|
|
|
|
.. automethod:: PIL.Image.Image.crop
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2023-02-18 12:34:52 +03:00
|
|
|
|
This crops the input image with the provided coordinates::
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2019-06-24 10:45:53 +03:00
|
|
|
|
from PIL import Image
|
2019-06-24 11:04:13 +03:00
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
with Image.open("hopper.jpg") as im:
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
# The crop method from the Image module takes four coordinates as input.
|
|
|
|
|
# The right can also be represented as (left+width)
|
|
|
|
|
# and lower can be represented as (upper+height).
|
|
|
|
|
(left, upper, right, lower) = (20, 20, 100, 100)
|
2019-06-24 10:45:53 +03:00
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
# Here the image "im" is cropped and assigned to new variable im_crop
|
|
|
|
|
im_crop = im.crop((left, upper, right, lower))
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
|
|
|
|
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.draft
|
2020-06-22 11:55:54 +03:00
|
|
|
|
.. automethod:: PIL.Image.Image.effect_spread
|
|
|
|
|
.. automethod:: PIL.Image.Image.entropy
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.filter
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2023-02-18 12:34:52 +03:00
|
|
|
|
This blurs the input image using a filter from the ``ImageFilter`` module::
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2019-06-24 11:04:13 +03:00
|
|
|
|
from PIL import Image, ImageFilter
|
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
with Image.open("hopper.jpg") as im:
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
# Blur the input image using the filter ImageFilter.BLUR
|
|
|
|
|
im_blurred = im.filter(filter=ImageFilter.BLUR)
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2021-02-23 01:59:51 +03:00
|
|
|
|
.. automethod:: PIL.Image.Image.frombytes
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.getbands
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2023-02-18 12:34:52 +03:00
|
|
|
|
This helps to get the bands of the input image::
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2019-06-24 10:45:53 +03:00
|
|
|
|
from PIL import Image
|
2019-06-24 11:04:13 +03:00
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
with Image.open("hopper.jpg") as im:
|
|
|
|
|
print(im.getbands()) # Returns ('R', 'G', 'B')
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.getbbox
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2023-02-18 12:34:52 +03:00
|
|
|
|
This helps to get the bounding box coordinates of the input image::
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2019-06-24 10:45:53 +03:00
|
|
|
|
from PIL import Image
|
2019-06-24 11:04:13 +03:00
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
with Image.open("hopper.jpg") as im:
|
|
|
|
|
print(im.getbbox())
|
|
|
|
|
# Returns four coordinates in the format (left, upper, right, lower)
|
2019-06-24 10:45:53 +03:00
|
|
|
|
|
2020-06-22 11:55:54 +03:00
|
|
|
|
.. automethod:: PIL.Image.Image.getchannel
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.getcolors
|
|
|
|
|
.. automethod:: PIL.Image.Image.getdata
|
2020-04-11 11:01:13 +03:00
|
|
|
|
.. automethod:: PIL.Image.Image.getexif
|
2020-06-22 11:55:54 +03:00
|
|
|
|
.. automethod:: PIL.Image.Image.getextrema
|
2014-11-10 07:51:20 +03:00
|
|
|
|
.. automethod:: PIL.Image.Image.getpalette
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.getpixel
|
2020-06-22 11:55:54 +03:00
|
|
|
|
.. automethod:: PIL.Image.Image.getprojection
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.histogram
|
|
|
|
|
.. automethod:: PIL.Image.Image.paste
|
|
|
|
|
.. automethod:: PIL.Image.Image.point
|
|
|
|
|
.. automethod:: PIL.Image.Image.putalpha
|
|
|
|
|
.. automethod:: PIL.Image.Image.putdata
|
|
|
|
|
.. automethod:: PIL.Image.Image.putpalette
|
|
|
|
|
.. automethod:: PIL.Image.Image.putpixel
|
|
|
|
|
.. automethod:: PIL.Image.Image.quantize
|
2020-06-22 11:55:54 +03:00
|
|
|
|
.. automethod:: PIL.Image.Image.reduce
|
|
|
|
|
.. automethod:: PIL.Image.Image.remap_palette
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.resize
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2023-02-18 12:34:52 +03:00
|
|
|
|
This resizes the given image from ``(width, height)`` to ``(width/2, height/2)``::
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2019-06-24 10:45:53 +03:00
|
|
|
|
from PIL import Image
|
2019-06-24 11:04:13 +03:00
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
with Image.open("hopper.jpg") as im:
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
# Provide the target width and height of the image
|
|
|
|
|
(width, height) = (im.width // 2, im.height // 2)
|
|
|
|
|
im_resized = im.resize((width, height))
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.rotate
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2023-02-18 12:34:52 +03:00
|
|
|
|
This rotates the input image by ``theta`` degrees counter clockwise::
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2019-06-24 10:45:53 +03:00
|
|
|
|
from PIL import Image
|
2019-06-24 11:04:13 +03:00
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
with Image.open("hopper.jpg") as im:
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
# Rotate the image by 60 degrees counter clockwise
|
|
|
|
|
theta = 60
|
|
|
|
|
# Angle is in degrees counter clockwise
|
|
|
|
|
im_rotated = im.rotate(angle=theta)
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.save
|
|
|
|
|
.. automethod:: PIL.Image.Image.seek
|
|
|
|
|
.. automethod:: PIL.Image.Image.show
|
|
|
|
|
.. automethod:: PIL.Image.Image.split
|
|
|
|
|
.. automethod:: PIL.Image.Image.tell
|
|
|
|
|
.. automethod:: PIL.Image.Image.thumbnail
|
|
|
|
|
.. automethod:: PIL.Image.Image.tobitmap
|
2014-09-23 14:56:22 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.tobytes
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.transform
|
|
|
|
|
.. automethod:: PIL.Image.Image.transpose
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2022-09-03 13:53:22 +03:00
|
|
|
|
This flips the input image by using the :data:`Transpose.FLIP_LEFT_RIGHT`
|
2023-02-24 00:17:10 +03:00
|
|
|
|
method. ::
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2019-06-24 10:45:53 +03:00
|
|
|
|
from PIL import Image
|
2019-06-24 11:04:13 +03:00
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
with Image.open("hopper.jpg") as im:
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2021-02-25 15:41:31 +03:00
|
|
|
|
# Flip the image from left to right
|
2022-01-15 01:02:31 +03:00
|
|
|
|
im_flipped = im.transpose(method=Image.Transpose.FLIP_LEFT_RIGHT)
|
2021-02-25 15:41:31 +03:00
|
|
|
|
# To flip the image from top to bottom,
|
2022-01-15 01:02:31 +03:00
|
|
|
|
# use the method "Image.Transpose.FLIP_TOP_BOTTOM"
|
2019-06-24 10:45:53 +03:00
|
|
|
|
|
2019-04-06 23:42:22 +03:00
|
|
|
|
|
2013-10-12 09:18:28 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.verify
|
|
|
|
|
|
|
|
|
|
.. automethod:: PIL.Image.Image.load
|
2014-04-18 08:53:49 +04:00
|
|
|
|
.. automethod:: PIL.Image.Image.close
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
2020-07-09 20:48:42 +03:00
|
|
|
|
Image Attributes
|
|
|
|
|
----------------
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
|
|
|
|
Instances of the :py:class:`Image` class have the following attributes:
|
|
|
|
|
|
2020-06-22 09:59:57 +03:00
|
|
|
|
.. py:attribute:: Image.filename
|
|
|
|
|
:type: str
|
2017-07-13 23:35:40 +03:00
|
|
|
|
|
2018-01-27 09:04:46 +03:00
|
|
|
|
The filename or path of the source file. Only images created with the
|
2019-09-05 23:49:31 +03:00
|
|
|
|
factory function ``open`` have a filename attribute. If the input is a
|
2017-07-13 23:35:40 +03:00
|
|
|
|
file like object, the filename attribute is set to an empty string.
|
2018-01-27 09:04:46 +03:00
|
|
|
|
|
2020-06-22 09:59:57 +03:00
|
|
|
|
.. py:attribute:: Image.format
|
|
|
|
|
:type: Optional[str]
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
|
|
|
|
The file format of the source file. For images created by the library
|
|
|
|
|
itself (via a factory function, or by running a method on an existing
|
2020-07-10 00:50:57 +03:00
|
|
|
|
image), this attribute is set to :data:`None`.
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
2020-06-22 09:59:57 +03:00
|
|
|
|
.. py:attribute:: Image.mode
|
|
|
|
|
:type: str
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
|
|
|
|
Image mode. This is a string specifying the pixel format used by the image.
|
|
|
|
|
Typical values are “1”, “L”, “RGB”, or “CMYK.” See
|
2014-11-19 23:49:27 +03:00
|
|
|
|
:ref:`concept-modes` for a full list.
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
2020-06-22 09:59:57 +03:00
|
|
|
|
.. py:attribute:: Image.size
|
|
|
|
|
:type: tuple[int]
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
|
|
|
|
Image size, in pixels. The size is given as a 2-tuple (width, height).
|
|
|
|
|
|
2020-06-22 09:59:57 +03:00
|
|
|
|
.. py:attribute:: Image.width
|
|
|
|
|
:type: int
|
2015-06-26 13:14:26 +03:00
|
|
|
|
|
|
|
|
|
Image width, in pixels.
|
|
|
|
|
|
2020-06-22 09:59:57 +03:00
|
|
|
|
.. py:attribute:: Image.height
|
|
|
|
|
:type: int
|
2015-06-26 13:14:26 +03:00
|
|
|
|
|
|
|
|
|
Image height, in pixels.
|
|
|
|
|
|
2020-06-22 09:59:57 +03:00
|
|
|
|
.. py:attribute:: Image.palette
|
|
|
|
|
:type: Optional[PIL.ImagePalette.ImagePalette]
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
2019-05-18 13:36:22 +03:00
|
|
|
|
Colour palette table, if any. If mode is "P" or "PA", this should be an
|
|
|
|
|
instance of the :py:class:`~PIL.ImagePalette.ImagePalette` class.
|
2020-07-10 00:50:57 +03:00
|
|
|
|
Otherwise, it should be set to :data:`None`.
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
2020-06-22 09:59:57 +03:00
|
|
|
|
.. py:attribute:: Image.info
|
|
|
|
|
:type: dict
|
2013-10-12 09:18:28 +04:00
|
|
|
|
|
|
|
|
|
A dictionary holding data associated with the image. This dictionary is
|
|
|
|
|
used by file handlers to pass on various non-image information read from
|
|
|
|
|
the file. See documentation for the various file handlers for details.
|
|
|
|
|
|
|
|
|
|
Most methods ignore the dictionary when returning new images; since the
|
|
|
|
|
keys are not standardized, it’s not possible for a method to know if the
|
|
|
|
|
operation affects the dictionary. If you need the information later on,
|
|
|
|
|
keep a reference to the info dictionary returned from the open method.
|
|
|
|
|
|
2015-02-10 21:15:47 +03:00
|
|
|
|
Unless noted elsewhere, this dictionary does not affect saving files.
|
2014-11-20 02:40:49 +03:00
|
|
|
|
|
2020-06-27 18:24:13 +03:00
|
|
|
|
.. py:attribute:: Image.is_animated
|
|
|
|
|
:type: bool
|
|
|
|
|
|
2020-07-05 14:47:23 +03:00
|
|
|
|
``True`` if this image has more than one frame, or ``False`` otherwise.
|
2020-06-27 18:24:13 +03:00
|
|
|
|
|
2020-07-05 14:47:23 +03:00
|
|
|
|
This attribute is only defined by image plugins that support animated images.
|
2020-06-27 18:24:13 +03:00
|
|
|
|
Plugins may leave this attribute undefined if they don't support loading
|
2020-07-05 14:47:23 +03:00
|
|
|
|
animated images, even if the given format supports animated images.
|
|
|
|
|
|
2020-07-09 18:16:41 +03:00
|
|
|
|
Given that this attribute is not present for all images use
|
|
|
|
|
``getattr(image, "is_animated", False)`` to check if Pillow is aware of multiple
|
|
|
|
|
frames in an image regardless of its format.
|
2020-06-27 18:24:13 +03:00
|
|
|
|
|
|
|
|
|
.. seealso:: :attr:`~Image.n_frames`, :func:`~Image.seek` and :func:`~Image.tell`
|
|
|
|
|
|
|
|
|
|
.. py:attribute:: Image.n_frames
|
|
|
|
|
:type: int
|
|
|
|
|
|
|
|
|
|
The number of frames in this image.
|
|
|
|
|
|
2020-07-05 14:47:23 +03:00
|
|
|
|
This attribute is only defined by image plugins that support animated images.
|
2020-06-27 18:24:13 +03:00
|
|
|
|
Plugins may leave this attribute undefined if they don't support loading
|
2020-07-05 14:47:23 +03:00
|
|
|
|
animated images, even if the given format supports animated images.
|
|
|
|
|
|
2020-07-09 18:16:41 +03:00
|
|
|
|
Given that this attribute is not present for all images use
|
|
|
|
|
``getattr(image, "n_frames", 1)`` to check the number of frames that Pillow is
|
|
|
|
|
aware of in an image regardless of its format.
|
2020-06-27 18:24:13 +03:00
|
|
|
|
|
|
|
|
|
.. seealso:: :attr:`~Image.is_animated`, :func:`~Image.seek` and :func:`~Image.tell`
|
2020-07-02 14:58:09 +03:00
|
|
|
|
|
2023-09-30 03:14:10 +03:00
|
|
|
|
.. autoattribute:: PIL.Image.Image.has_transparency_data
|
|
|
|
|
|
2020-07-09 20:48:42 +03:00
|
|
|
|
Classes
|
|
|
|
|
-------
|
|
|
|
|
|
2020-07-10 01:47:30 +03:00
|
|
|
|
.. autoclass:: PIL.Image.Exif
|
|
|
|
|
:members:
|
|
|
|
|
:undoc-members:
|
|
|
|
|
:show-inheritance:
|
2020-07-09 20:48:42 +03:00
|
|
|
|
.. autoclass:: PIL.Image.ImagePointHandler
|
|
|
|
|
.. autoclass:: PIL.Image.ImageTransformHandler
|
|
|
|
|
|
2024-05-10 12:48:36 +03:00
|
|
|
|
Protocols
|
|
|
|
|
---------
|
|
|
|
|
|
2024-05-11 04:16:52 +03:00
|
|
|
|
.. autoclass:: SupportsArrayInterface
|
|
|
|
|
:show-inheritance:
|
2024-05-10 12:48:36 +03:00
|
|
|
|
.. autoclass:: SupportsGetData
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
2020-06-22 09:45:18 +03:00
|
|
|
|
Constants
|
|
|
|
|
---------
|
|
|
|
|
|
|
|
|
|
.. data:: NONE
|
2020-07-20 14:16:33 +03:00
|
|
|
|
.. data:: MAX_IMAGE_PIXELS
|
|
|
|
|
|
2020-07-20 16:08:25 +03:00
|
|
|
|
Set to 89,478,485, approximately 0.25GB for a 24-bit (3 bpp) image.
|
2020-07-20 14:16:33 +03:00
|
|
|
|
See :py:meth:`~PIL.Image.open` for more information about how this is used.
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
|
|
|
|
Transpose methods
|
|
|
|
|
^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
Used to specify the :meth:`Image.transpose` method to use.
|
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. autoclass:: Transpose
|
|
|
|
|
:members:
|
|
|
|
|
:undoc-members:
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
|
|
|
|
Transform methods
|
|
|
|
|
^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
Used to specify the :meth:`Image.transform` method to use.
|
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. py:class:: Transform
|
|
|
|
|
|
|
|
|
|
.. py:attribute:: AFFINE
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
Affine transform
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. py:attribute:: EXTENT
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
Cut out a rectangular subregion
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. py:attribute:: PERSPECTIVE
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
Perspective transform
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. py:attribute:: QUAD
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
Map a quadrilateral to a rectangle
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. py:attribute:: MESH
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
Map a number of source quadrilaterals in one operation
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
|
|
|
|
Resampling filters
|
|
|
|
|
^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
See :ref:`concept-filters` for details.
|
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. autoclass:: Resampling
|
|
|
|
|
:members:
|
|
|
|
|
:undoc-members:
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
|
|
|
|
Dither modes
|
|
|
|
|
^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
Used to specify the dithering method to use for the
|
|
|
|
|
:meth:`~Image.convert` and :meth:`~Image.quantize` methods.
|
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. py:class:: Dither
|
|
|
|
|
|
|
|
|
|
.. py:attribute:: NONE
|
|
|
|
|
|
|
|
|
|
No dither
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. py:attribute:: ORDERED
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
Not implemented
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. py:attribute:: RASTERIZE
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
Not implemented
|
|
|
|
|
|
|
|
|
|
.. py:attribute:: FLOYDSTEINBERG
|
|
|
|
|
|
|
|
|
|
Floyd-Steinberg dither
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
|
|
|
|
Palettes
|
|
|
|
|
^^^^^^^^
|
|
|
|
|
|
2023-04-19 15:46:58 +03:00
|
|
|
|
Used to specify the palette to use for the :meth:`~Image.convert` method.
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. autoclass:: Palette
|
|
|
|
|
:members:
|
|
|
|
|
:undoc-members:
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
|
|
|
|
Quantization methods
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
Used to specify the quantization method to use for the :meth:`~Image.quantize` method.
|
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. py:class:: Quantize
|
|
|
|
|
|
|
|
|
|
.. py:attribute:: MEDIANCUT
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
Median cut. Default method, except for RGBA images. This method does not support
|
|
|
|
|
RGBA images.
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. py:attribute:: MAXCOVERAGE
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
Maximum coverage. This method does not support RGBA images.
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. py:attribute:: FASTOCTREE
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
Fast octree. Default method for RGBA images.
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
.. py:attribute:: LIBIMAGEQUANT
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
libimagequant
|
2020-06-22 09:45:18 +03:00
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
Check support using :py:func:`PIL.features.check_feature` with
|
|
|
|
|
``feature="libimagequant"``.
|