ImagePath Module ################ class Path ********** compact ======= :doc: https://pillow.readthedocs.io/en/latest/reference/ImagePath.html#PIL.ImagePath.PIL.ImagePath.Path.compact, http://effbot.org/imagingbook/imagepath.htm#tag-ImagePath.Path.compact .. |ImagePath_compact_01.res1p| image:: _static/exams/result/ImagePath_compact_01_1p.jpg .. |ImagePath_compact_01.res2p| image:: _static/exams/result/ImagePath_compact_01_2p.jpg .. |ImagePath_compact_01.res3p| image:: _static/exams/result/ImagePath_compact_01_3p.jpg .. |ImagePath_compact_01.res1l| image:: _static/exams/result/ImagePath_compact_01_1l.jpg .. |ImagePath_compact_01.res2l| image:: _static/exams/result/ImagePath_compact_01_2l.jpg .. |ImagePath_compact_01.res3l| image:: _static/exams/result/ImagePath_compact_01_3l.jpg .. list-table:: :widths: 20 10 10 * - .. literalinclude:: _static/exams/ImagePath_compact_01.py - | original | |ImagePath_compact_01.res1l| | | compact(distance=4) | |ImagePath_compact_01.res2l| | | compact(distance=6) | |ImagePath_compact_01.res3l| - | | |ImagePath_compact_01.res1p| | | | |ImagePath_compact_01.res2p| | | | |ImagePath_compact_01.res3p| .. |ImagePath_compact_02.res0| image:: _static/exams/result/ImagePath_compact_02_0.jpg .. |ImagePath_compact_02.res1| image:: _static/exams/result/ImagePath_compact_02_1.jpg .. |ImagePath_compact_02.res2| image:: _static/exams/result/ImagePath_compact_02_2.jpg .. |ImagePath_compact_02.res3| image:: _static/exams/result/ImagePath_compact_02_3.jpg .. |ImagePath_compact_02.res4| image:: _static/exams/result/ImagePath_compact_02_4.jpg .. literalinclude:: _static/exams/ImagePath_compact_02.py .. list-table:: * - | original | |ImagePath_compact_02.res0| - | compact | |ImagePath_compact_02.res1| - | more compact | |ImagePath_compact_02.res2| - | more compact | |ImagePath_compact_02.res3| - | more compact | |ImagePath_compact_02.res4| getbbox ======= :doc: https://pillow.readthedocs.io/en/latest/reference/ImagePath.html#PIL.ImagePath.PIL.ImagePath.Path.getbbox, http://effbot.org/imagingbook/imagepath.htm#tag-ImagePath.Path.getbbox .. code-block:: pycon >>> import math >>> from PIL import ImagePath >>> # integers ... xy = list(zip(range(3, 10, 1), range(24, 5, -2))) >>> xy [(3, 24), (4, 22), (5, 20), (6, 18), (7, 16), (8, 14), (9, 12)] >>> bb = ImagePath.Path(xy).getbbox() >>> bb (3.0, 12.0, 9.0, 24.0) >>> list(map(int, bb)) [3, 12, 9, 24] >>> # floating points ... xy = list(zip([i / 4. for i in range(3, 10, 1)], [i / 2. for i in range(24, 5, -2)])) >>> xy [(0.75, 12.0), (1.0, 11.0), (1.25, 10.0), (1.5, 9.0), (1.75, 8.0), (2.0, 7.0), (2.25, 6.0)] >>> bb = ImagePath.Path(xy).getbbox() >>> bb (0.75, 6.0, 2.25, 12.0) >>> list(map(int, map(math.floor, bb[:2]))) # (left, top) [0, 6] >>> list(map(int, map(math.ceil, bb[2:]))) # (right, bottom) [3, 12] map === :doc: https://pillow.readthedocs.io/en/latest/reference/ImagePath.html#PIL.ImagePath.PIL.ImagePath.Path.map, http://effbot.org/imagingbook/imagepath.htm#tag-ImagePath.Path.map .. code-block:: pycon >>> from PIL import ImagePath >>> xy = list(zip(range(3, 8, 1), range(22, 5, -2))) >>> xy [(3, 22), (4, 20), (5, 18), (6, 16), (7, 14)] >>> aspath = ImagePath.Path(xy) >>> aspath.tolist() [(3.0, 22.0), (4.0, 20.0), (5.0, 18.0), (6.0, 16.0), (7.0, 14.0)] >>> # map method modifies the path in place, ... aspath.map(lambda x, y: (x * 2, y * 3)) >>> aspath.tolist() [(6.0, 66.0), (8.0, 60.0), (10.0, 54.0), (12.0, 48.0), (14.0, 42.0)] >>> def _fun(x, y): ... return (x - 10, y - 30) ... >>> aspath.map(_fun) # map method modifies the path in place, >>> aspath.tolist() [(-4.0, 36.0), (-2.0, 30.0), (0.0, 24.0), (2.0, 18.0), (4.0, 12.0)] tolist ====== :doc: https://pillow.readthedocs.io/en/latest/reference/ImagePath.html#PIL.ImagePath.PIL.ImagePath.Path.tolist, http://effbot.org/imagingbook/imagepath.htm#tag-ImagePath.Path.tolist .. code-block:: pycon >>> from PIL import ImagePath >>> xy = list(zip(range(3, 8, 1), range(22, 5, -2))) >>> xy [(3, 22), (4, 20), (5, 18), (6, 16), (7, 14)] >>> aspath = ImagePath.Path(xy) >>> aspath.tolist() [(3.0, 22.0), (4.0, 20.0), (5.0, 18.0), (6.0, 16.0), (7.0, 14.0)] >>> aspath.tolist(True) [3.0, 22.0, 4.0, 20.0, 5.0, 18.0, 6.0, 16.0, 7.0, 14.0] transform ========= :doc: https://pillow.readthedocs.io/en/latest/reference/ImagePath.html#PIL.ImagePath.PIL.ImagePath.Path.transform, http://effbot.org/imagingbook/imagepath.htm#tag-ImagePath.Path.transform .. |ImagePath_transform.res01| image:: _static/exams/result/ImagePath_transform_01_0.jpg .. |ImagePath_transform.res02| image:: _static/exams/result/ImagePath_transform_01_1.jpg .. list-table:: :widths: 20 10 10 * - .. literalinclude:: _static/exams/ImagePath_transform_01.py - | |ImagePath_transform.res01| | orig | - | |ImagePath_transform.res02| | affine transform |