diff --git a/Tests/images/imagedraw_rectangle_translucent_outline.png b/Tests/images/imagedraw_rectangle_translucent_outline.png new file mode 100644 index 00000000000..845648762cc Binary files /dev/null and b/Tests/images/imagedraw_rectangle_translucent_outline.png differ diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 9c95ed2551a..7b1faadb795 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -692,6 +692,20 @@ def test_rectangle_I16(): assert_image_equal_tofile(im.convert("I"), "Tests/images/imagedraw_rectangle_I.png") +def test_rectangle_translucent_outline(): + # Arrange + im = Image.new("RGB", (W, H)) + draw = ImageDraw.Draw(im, "RGBA") + + # Act + draw.rectangle(BBOX1, fill="black", outline=(0, 255, 0, 127), width=5) + + # Assert + assert_image_equal_tofile( + im, "Tests/images/imagedraw_rectangle_translucent_outline.png" + ) + + def test_floodfill(): red = ImageColor.getrgb("red") diff --git a/src/libImaging/Draw.c b/src/libImaging/Draw.c index 8471ffb178d..b6f63b7e804 100644 --- a/src/libImaging/Draw.c +++ b/src/libImaging/Draw.c @@ -724,8 +724,8 @@ ImagingDrawRectangle( for (i = 0; i < width; i++) { draw->hline(im, x0, y0 + i, x1, ink); draw->hline(im, x0, y1 - i, x1, ink); - draw->line(im, x1 - i, y0, x1 - i, y1, ink); - draw->line(im, x0 + i, y1, x0 + i, y0, ink); + draw->line(im, x1 - i, y0 + width, x1 - i, y1 - width + 1, ink); + draw->line(im, x0 + i, y0 + width, x0 + i, y1 - width + 1, ink); } }