mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Added width argument to regular_polygon
This commit is contained in:
parent
7ec3f8ce52
commit
3fc446c277
BIN
Tests/images/imagedraw_triangle_width.png
Normal file
BIN
Tests/images/imagedraw_triangle_width.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 499 B |
|
@ -1347,20 +1347,20 @@ def test_same_color_outline():
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"n_sides, rotation, polygon_name",
|
"n_sides, polygon_name, args",
|
||||||
[(4, 0, "square"), (8, 0, "regular_octagon"), (4, 45, "square")],
|
[
|
||||||
|
(4, "square", {}),
|
||||||
|
(8, "regular_octagon", {}),
|
||||||
|
(4, "square_rotate_45", {"rotation": 45}),
|
||||||
|
(3, "triangle_width", {"width": 5, "outline": "yellow"}),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
def test_draw_regular_polygon(n_sides, rotation, polygon_name):
|
def test_draw_regular_polygon(n_sides, polygon_name, args):
|
||||||
im = Image.new("RGBA", size=(W, H), color=(255, 0, 0, 0))
|
im = Image.new("RGBA", size=(W, H), color=(255, 0, 0, 0))
|
||||||
filename_base = f"Tests/images/imagedraw_{polygon_name}"
|
filename = f"Tests/images/imagedraw_{polygon_name}.png"
|
||||||
filename = (
|
|
||||||
f"{filename_base}.png"
|
|
||||||
if rotation == 0
|
|
||||||
else f"{filename_base}_rotate_{rotation}.png"
|
|
||||||
)
|
|
||||||
draw = ImageDraw.Draw(im)
|
draw = ImageDraw.Draw(im)
|
||||||
bounding_circle = ((W // 2, H // 2), 25)
|
bounding_circle = ((W // 2, H // 2), 25)
|
||||||
draw.regular_polygon(bounding_circle, n_sides, rotation=rotation, fill="red")
|
draw.regular_polygon(bounding_circle, n_sides, fill="red", **args)
|
||||||
assert_image_equal_tofile(im, filename)
|
assert_image_equal_tofile(im, filename)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -296,7 +296,7 @@ Methods
|
||||||
:param width: The line width, in pixels.
|
:param width: The line width, in pixels.
|
||||||
|
|
||||||
|
|
||||||
.. py:method:: ImageDraw.regular_polygon(bounding_circle, n_sides, rotation=0, fill=None, outline=None)
|
.. py:method:: ImageDraw.regular_polygon(bounding_circle, n_sides, rotation=0, fill=None, outline=None, width=1)
|
||||||
|
|
||||||
Draws a regular polygon inscribed in ``bounding_circle``,
|
Draws a regular polygon inscribed in ``bounding_circle``,
|
||||||
with ``n_sides``, and rotation of ``rotation`` degrees.
|
with ``n_sides``, and rotation of ``rotation`` degrees.
|
||||||
|
@ -311,6 +311,7 @@ Methods
|
||||||
(e.g. ``rotation=90``, applies a 90 degree rotation).
|
(e.g. ``rotation=90``, applies a 90 degree rotation).
|
||||||
:param fill: Color to use for the fill.
|
:param fill: Color to use for the fill.
|
||||||
:param outline: Color to use for the outline.
|
:param outline: Color to use for the outline.
|
||||||
|
:param width: The line width, in pixels.
|
||||||
|
|
||||||
|
|
||||||
.. py:method:: ImageDraw.rectangle(xy, fill=None, outline=None, width=1)
|
.. py:method:: ImageDraw.rectangle(xy, fill=None, outline=None, width=1)
|
||||||
|
|
|
@ -279,11 +279,11 @@ class ImageDraw:
|
||||||
self.im.paste(im.im, (0, 0) + im.size, mask.im)
|
self.im.paste(im.im, (0, 0) + im.size, mask.im)
|
||||||
|
|
||||||
def regular_polygon(
|
def regular_polygon(
|
||||||
self, bounding_circle, n_sides, rotation=0, fill=None, outline=None
|
self, bounding_circle, n_sides, rotation=0, fill=None, outline=None, width=1
|
||||||
):
|
):
|
||||||
"""Draw a regular polygon."""
|
"""Draw a regular polygon."""
|
||||||
xy = _compute_regular_polygon_vertices(bounding_circle, n_sides, rotation)
|
xy = _compute_regular_polygon_vertices(bounding_circle, n_sides, rotation)
|
||||||
self.polygon(xy, fill, outline)
|
self.polygon(xy, fill, outline, width)
|
||||||
|
|
||||||
def rectangle(self, xy, fill=None, outline=None, width=1):
|
def rectangle(self, xy, fill=None, outline=None, width=1):
|
||||||
"""Draw a rectangle."""
|
"""Draw a rectangle."""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user