diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 3bcb7b90178..e017e7a97de 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -945,6 +945,21 @@ def test_rounded_rectangle_zero_radius(bbox: Coords) -> None: assert_image_equal_tofile(im, "Tests/images/imagedraw_rectangle_width_fill.png") +@pytest.mark.parametrize("w, h", ((200, 100), (100, 200))) +def test_rounded_rectangle_large_radius(w: int, h: int) -> None: + im = Image.new("RGB", (w, h)) + draw = ImageDraw.Draw(im) + draw.rounded_rectangle( + (0, 0, w, h), 100, "red", corners=(True, False, False, False) + ) + + expected = Image.new("RGB", (w, h)) + draw = ImageDraw.Draw(expected) + draw.rounded_rectangle((0, 0, w, h), 50, "red", corners=(True, False, False, False)) + + assert_image_equal(im, expected) + + @pytest.mark.parametrize( "xy, suffix", [ diff --git a/docs/reference/ImageDraw.rst b/docs/reference/ImageDraw.rst index 4c956759334..f9f3a42fafd 100644 --- a/docs/reference/ImageDraw.rst +++ b/docs/reference/ImageDraw.rst @@ -382,7 +382,8 @@ Methods :param xy: Two points to define the bounding box. Sequence of either ``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``, where ``x1 >= x0`` and ``y1 >= y0``. The bounding box is inclusive of both endpoints. - :param radius: Radius of the corners. + :param radius: Radius of the corners, limited to half of the smallest dimension of + the bounding box. :param fill: Color to use for the fill. :param outline: Color to use for the outline. :param width: The line width, in pixels. diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index 9b0864d1a89..5aae16fddbf 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -419,7 +419,7 @@ def rounded_rectangle( if corners is None: corners = (True, True, True, True) - d = radius * 2 + d = min(x1 - x0, y1 - y0, radius * 2) x0 = round(x0) y0 = round(y0)