Skip to content

Commit c46cf19

Browse files
authored
Merge pull request #7684 from nulano/docs-imagetransform
Improve ImageTransform documentation
2 parents 4233dd7 + fc7088a commit c46cf19

5 files changed

Lines changed: 48 additions & 13 deletions

File tree

docs/PIL.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ can be found here.
7777
:undoc-members:
7878
:show-inheritance:
7979

80-
:mod:`~PIL.ImageTransform` Module
81-
---------------------------------
82-
83-
.. automodule:: PIL.ImageTransform
84-
:members:
85-
:undoc-members:
86-
:show-inheritance:
87-
8880
:mod:`~PIL.PaletteFile` Module
8981
------------------------------
9082

docs/reference/ImageTransform.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
.. py:module:: PIL.ImageTransform
3+
.. py:currentmodule:: PIL.ImageTransform
4+
5+
:py:mod:`~PIL.ImageTransform` Module
6+
====================================
7+
8+
The :py:mod:`~PIL.ImageTransform` module contains implementations of
9+
:py:class:`~PIL.Image.ImageTransformHandler` for some of the builtin
10+
:py:class:`.Image.Transform` methods.
11+
12+
.. autoclass:: Transform
13+
:members:
14+
:undoc-members:
15+
:show-inheritance:
16+
17+
.. autoclass:: AffineTransform
18+
:members:
19+
:undoc-members:
20+
:show-inheritance:
21+
22+
.. autoclass:: ExtentTransform
23+
:members:
24+
:undoc-members:
25+
:show-inheritance:
26+
27+
.. autoclass:: QuadTransform
28+
:members:
29+
:undoc-members:
30+
:show-inheritance:
31+
32+
.. autoclass:: MeshTransform
33+
:members:
34+
:undoc-members:
35+
:show-inheritance:

docs/reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Reference
2525
ImageShow
2626
ImageStat
2727
ImageTk
28+
ImageTransform
2829
ImageWin
2930
ExifTags
3031
TiffTags

src/PIL/Image.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,6 +2666,10 @@ class Example(Image.ImageTransformHandler):
26662666
def transform(self, size, data, resample, fill=1):
26672667
# Return result
26682668
2669+
Implementations of :py:class:`~PIL.Image.ImageTransformHandler`
2670+
for some of the :py:class:`Transform` methods are provided
2671+
in :py:mod:`~PIL.ImageTransform`.
2672+
26692673
It may also be an object with a ``method.getdata`` method
26702674
that returns a tuple supplying new ``method`` and ``data`` values::
26712675

src/PIL/ImageTransform.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020

2121

2222
class Transform(Image.ImageTransformHandler):
23+
"""Base class for other transforms defined in :py:mod:`~PIL.ImageTransform`."""
24+
2325
method: Image.Transform
2426

2527
def __init__(self, data: Sequence[int]) -> None:
2628
self.data = data
2729

28-
def getdata(self) -> tuple[int, Sequence[int]]:
30+
def getdata(self) -> tuple[Image.Transform, Sequence[int]]:
2931
return self.method, self.data
3032

3133
def transform(
@@ -34,6 +36,7 @@ def transform(
3436
image: Image.Image,
3537
**options: dict[str, str | int | tuple[int, ...] | list[int]],
3638
) -> Image.Image:
39+
"""Perform the transform. Called from :py:meth:`.Image.transform`."""
3740
# can be overridden
3841
method, data = self.getdata()
3942
return image.transform(size, method, data, **options)
@@ -51,7 +54,7 @@ class AffineTransform(Transform):
5154
This function can be used to scale, translate, rotate, and shear the
5255
original image.
5356
54-
See :py:meth:`~PIL.Image.Image.transform`
57+
See :py:meth:`.Image.transform`
5558
5659
:param matrix: A 6-tuple (a, b, c, d, e, f) containing the first two rows
5760
from an affine transform matrix.
@@ -73,7 +76,7 @@ class ExtentTransform(Transform):
7376
rectangle in the current image. It is slightly slower than crop, but about
7477
as fast as a corresponding resize operation.
7578
76-
See :py:meth:`~PIL.Image.Image.transform`
79+
See :py:meth:`.Image.transform`
7780
7881
:param bbox: A 4-tuple (x0, y0, x1, y1) which specifies two points in the
7982
input image's coordinate system. See :ref:`coordinate-system`.
@@ -89,7 +92,7 @@ class QuadTransform(Transform):
8992
Maps a quadrilateral (a region defined by four corners) from the image to a
9093
rectangle of the given size.
9194
92-
See :py:meth:`~PIL.Image.Image.transform`
95+
See :py:meth:`.Image.transform`
9396
9497
:param xy: An 8-tuple (x0, y0, x1, y1, x2, y2, x3, y3) which contain the
9598
upper left, lower left, lower right, and upper right corner of the
@@ -104,7 +107,7 @@ class MeshTransform(Transform):
104107
Define a mesh image transform. A mesh transform consists of one or more
105108
individual quad transforms.
106109
107-
See :py:meth:`~PIL.Image.Image.transform`
110+
See :py:meth:`.Image.transform`
108111
109112
:param data: A list of (bbox, quad) tuples.
110113
"""

0 commit comments

Comments
 (0)