From 3bc17b8c680073473e384a6eeda107a048c13853 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 24 Nov 2026 18:37:37 +1100 Subject: [PATCH] Fix drawing dashed rectangle with two tuple coords --- Tests/test_imagedraw.py | 2 +- src/PIL/ImageDraw.py | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 059ce295356..1d1cab5fd52 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -1845,7 +1845,7 @@ def test_dash_rectangle() -> None: # Act draw.rectangle([10, 10, 90, 90], outline="green", dash=(10, 5)) - draw.rectangle([30, 30, 70, 70], fill="red", outline="green", dash=(10, 5)) + draw.rectangle([(30, 30), (70, 70)], fill="red", outline="green", dash=(10, 5)) # Assert assert_image_equal_tofile(im, "Tests/images/imagedraw_dash_rectangle.png") diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index 210b76085ec..fa435de7c3f 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -417,17 +417,9 @@ def rectangle( if len(dash) == 0 or any(not isinstance(v, int) for v in dash): msg = "dash must be a non-empty tuple of ints" raise ValueError(msg) + (x0, y0), (x1, y1) = self._normalize_coords(xy) self.draw.draw_lines( - [ - (xy[0], xy[1]), - (xy[2], xy[1]), - (xy[2], xy[3]), - (xy[0], xy[3]), - (xy[0], xy[1]), - ], - ink, - 1, - dash, + [(x0, y0), (x1, y0), (x1, y1), (x0, y1), (x0, y0)], ink, 1, dash ) else: self.draw.draw_rectangle(xy, ink, 0, width)