Skip to content

Commit 3a27118

Browse files
authored
Merge pull request #5183 from radarhere/rectangle
Only draw each rectangle outline pixel once
2 parents f15f573 + c0ee869 commit 3a27118

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed
235 Bytes
Loading

Tests/test_imagedraw.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,20 @@ def test_rectangle_I16():
692692
assert_image_equal_tofile(im.convert("I"), "Tests/images/imagedraw_rectangle_I.png")
693693

694694

695+
def test_rectangle_translucent_outline():
696+
# Arrange
697+
im = Image.new("RGB", (W, H))
698+
draw = ImageDraw.Draw(im, "RGBA")
699+
700+
# Act
701+
draw.rectangle(BBOX1, fill="black", outline=(0, 255, 0, 127), width=5)
702+
703+
# Assert
704+
assert_image_equal_tofile(
705+
im, "Tests/images/imagedraw_rectangle_translucent_outline.png"
706+
)
707+
708+
695709
def test_floodfill():
696710
red = ImageColor.getrgb("red")
697711

src/libImaging/Draw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,8 @@ ImagingDrawRectangle(
724724
for (i = 0; i < width; i++) {
725725
draw->hline(im, x0, y0 + i, x1, ink);
726726
draw->hline(im, x0, y1 - i, x1, ink);
727-
draw->line(im, x1 - i, y0, x1 - i, y1, ink);
728-
draw->line(im, x0 + i, y1, x0 + i, y0, ink);
727+
draw->line(im, x1 - i, y0 + width, x1 - i, y1 - width + 1, ink);
728+
draw->line(im, x0 + i, y0 + width, x0 + i, y1 - width + 1, ink);
729729
}
730730
}
731731

0 commit comments

Comments
 (0)