2013-10-13 09:17:45 +04:00
|
|
|
|
.. py:module:: PIL.ImageOps
|
|
|
|
|
.. py:currentmodule:: PIL.ImageOps
|
|
|
|
|
|
2020-06-22 06:52:50 +03:00
|
|
|
|
:py:mod:`~PIL.ImageOps` Module
|
|
|
|
|
==============================
|
2013-10-13 09:17:45 +04:00
|
|
|
|
|
2020-06-22 06:52:50 +03:00
|
|
|
|
The :py:mod:`~PIL.ImageOps` module contains a number of ‘ready-made’ image
|
2013-10-13 09:17:45 +04:00
|
|
|
|
processing operations. This module is somewhat experimental, and most operators
|
|
|
|
|
only work on L and RGB images.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 1.1.3
|
|
|
|
|
|
|
|
|
|
.. autofunction:: autocontrast
|
|
|
|
|
.. autofunction:: colorize
|
|
|
|
|
.. autofunction:: crop
|
2019-10-08 13:12:15 +03:00
|
|
|
|
.. autofunction:: scale
|
2024-02-29 12:16:41 +03:00
|
|
|
|
.. autoclass:: SupportsGetMesh
|
|
|
|
|
:show-inheritance:
|
2013-10-13 09:17:45 +04:00
|
|
|
|
.. autofunction:: deform
|
|
|
|
|
.. autofunction:: equalize
|
|
|
|
|
.. autofunction:: expand
|
|
|
|
|
.. autofunction:: flip
|
|
|
|
|
.. autofunction:: grayscale
|
|
|
|
|
.. autofunction:: invert
|
|
|
|
|
.. autofunction:: mirror
|
|
|
|
|
.. autofunction:: posterize
|
|
|
|
|
.. autofunction:: solarize
|
2019-10-08 13:12:15 +03:00
|
|
|
|
.. autofunction:: exif_transpose
|
2023-09-26 14:16:30 +03:00
|
|
|
|
|
2023-09-28 01:06:02 +03:00
|
|
|
|
.. _relative-resize:
|
|
|
|
|
|
2023-09-26 14:16:30 +03:00
|
|
|
|
Resize relative to a given size
|
|
|
|
|
-------------------------------
|
|
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
|
|
from PIL import Image, ImageOps
|
|
|
|
|
size = (100, 150)
|
|
|
|
|
with Image.open("Tests/images/hopper.png") as im:
|
|
|
|
|
ImageOps.contain(im, size).save("imageops_contain.png")
|
|
|
|
|
ImageOps.cover(im, size).save("imageops_cover.png")
|
|
|
|
|
ImageOps.fit(im, size).save("imageops_fit.png")
|
|
|
|
|
ImageOps.pad(im, size, color="#f00").save("imageops_pad.png")
|
|
|
|
|
|
2023-09-28 01:17:06 +03:00
|
|
|
|
# thumbnail() can also be used,
|
|
|
|
|
# but will modify the image object in place
|
|
|
|
|
im.thumbnail(size)
|
2023-09-29 11:29:45 +03:00
|
|
|
|
im.save("imageops_thumbnail.png")
|
|
|
|
|
|
|
|
|
|
+----------------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+
|
|
|
|
|
| | :py:meth:`~PIL.Image.Image.thumbnail` | :py:meth:`~PIL.ImageOps.contain` | :py:meth:`~PIL.ImageOps.cover` | :py:meth:`~PIL.ImageOps.fit` | :py:meth:`~PIL.ImageOps.pad` |
|
|
|
|
|
+================+===========================================+============================================+==========================================+========================================+========================================+
|
2023-10-15 23:07:08 +03:00
|
|
|
|
|Given size | ``(100, 150)`` | ``(100, 150)`` | ``(100, 150)`` | ``(100, 150)`` | ``(100, 150)`` |
|
2023-09-29 11:29:45 +03:00
|
|
|
|
+----------------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+
|
|
|
|
|
|Resulting image | .. image:: ../example/image_thumbnail.png | .. image:: ../example/imageops_contain.png | .. image:: ../example/imageops_cover.png | .. image:: ../example/imageops_fit.png | .. image:: ../example/imageops_pad.png |
|
|
|
|
|
+----------------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+
|
2023-10-15 23:07:08 +03:00
|
|
|
|
|Resulting size | ``100×100`` | ``100×100`` | ``150×150`` | ``100×150`` | ``100×150`` |
|
2023-09-29 11:29:45 +03:00
|
|
|
|
+----------------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+
|
2023-09-26 14:16:30 +03:00
|
|
|
|
|
|
|
|
|
.. autofunction:: contain
|
|
|
|
|
.. autofunction:: cover
|
|
|
|
|
.. autofunction:: fit
|
|
|
|
|
.. autofunction:: pad
|