mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Merge pull request #7132 from radarhere/regular_polygon_width
This commit is contained in:
commit
9636a2aaf1
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(
|
||||
"n_sides, rotation, polygon_name",
|
||||
[(4, 0, "square"), (8, 0, "regular_octagon"), (4, 45, "square")],
|
||||
"n_sides, polygon_name, args",
|
||||
[
|
||||
(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))
|
||||
filename_base = f"Tests/images/imagedraw_{polygon_name}"
|
||||
filename = (
|
||||
f"{filename_base}.png"
|
||||
if rotation == 0
|
||||
else f"{filename_base}_rotate_{rotation}.png"
|
||||
)
|
||||
filename = f"Tests/images/imagedraw_{polygon_name}.png"
|
||||
draw = ImageDraw.Draw(im)
|
||||
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)
|
||||
|
||||
|
||||
|
|
|
@ -296,7 +296,7 @@ Methods
|
|||
: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``,
|
||||
with ``n_sides``, and rotation of ``rotation`` degrees.
|
||||
|
@ -311,6 +311,7 @@ Methods
|
|||
(e.g. ``rotation=90``, applies a 90 degree rotation).
|
||||
:param fill: Color to use for the fill.
|
||||
: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)
|
||||
|
|
|
@ -279,11 +279,11 @@ class ImageDraw:
|
|||
self.im.paste(im.im, (0, 0) + im.size, mask.im)
|
||||
|
||||
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."""
|
||||
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):
|
||||
"""Draw a rectangle."""
|
||||
|
|
Loading…
Reference in New Issue
Block a user