Skip to content

Commit f5e9252

Browse files
committed
Fixed drawing a jointed line with a sequence of numeric values
1 parent 556c87c commit f5e9252

2 files changed

Lines changed: 89 additions & 25 deletions

File tree

Tests/test_imagedraw.py

Lines changed: 87 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -874,31 +874,93 @@ def test_wide_line_dot():
874874

875875

876876
def test_line_joint():
877-
im = Image.new("RGB", (500, 325))
878-
draw = ImageDraw.Draw(im)
879-
expected = "Tests/images/imagedraw_line_joint_curve.png"
880-
881-
# Act
882-
xy = [
883-
(400, 280),
884-
(380, 280),
885-
(450, 280),
886-
(440, 120),
887-
(350, 200),
888-
(310, 280),
889-
(300, 280),
890-
(250, 280),
891-
(250, 200),
892-
(150, 200),
893-
(150, 260),
894-
(50, 200),
895-
(150, 50),
896-
(250, 100),
897-
]
898-
draw.line(xy, GRAY, 50, "curve")
899-
900-
# Assert
901-
assert_image_similar(im, Image.open(expected), 3)
877+
for xy in [
878+
[
879+
(400, 280),
880+
(380, 280),
881+
(450, 280),
882+
(440, 120),
883+
(350, 200),
884+
(310, 280),
885+
(300, 280),
886+
(250, 280),
887+
(250, 200),
888+
(150, 200),
889+
(150, 260),
890+
(50, 200),
891+
(150, 50),
892+
(250, 100),
893+
],
894+
(
895+
400,
896+
280,
897+
380,
898+
280,
899+
450,
900+
280,
901+
440,
902+
120,
903+
350,
904+
200,
905+
310,
906+
280,
907+
300,
908+
280,
909+
250,
910+
280,
911+
250,
912+
200,
913+
150,
914+
200,
915+
150,
916+
260,
917+
50,
918+
200,
919+
150,
920+
50,
921+
250,
922+
100,
923+
),
924+
[
925+
400,
926+
280,
927+
380,
928+
280,
929+
450,
930+
280,
931+
440,
932+
120,
933+
350,
934+
200,
935+
310,
936+
280,
937+
300,
938+
280,
939+
250,
940+
280,
941+
250,
942+
200,
943+
150,
944+
200,
945+
150,
946+
260,
947+
50,
948+
200,
949+
150,
950+
50,
951+
250,
952+
100,
953+
],
954+
]:
955+
im = Image.new("RGB", (500, 325))
956+
draw = ImageDraw.Draw(im)
957+
expected = "Tests/images/imagedraw_line_joint_curve.png"
958+
959+
# Act
960+
draw.line(xy, GRAY, 50, "curve")
961+
962+
# Assert
963+
assert_image_similar(im, Image.open(expected), 3)
902964

903965

904966
def test_textsize_empty_string():

src/PIL/ImageDraw.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ def line(self, xy, fill=None, width=0, joint=None):
156156
if ink is not None:
157157
self.draw.draw_lines(xy, ink, width)
158158
if joint == "curve" and width > 4:
159+
if not isinstance(xy[0], (list, tuple)):
160+
xy = [tuple(xy[i : i + 2]) for i in range(0, len(xy), 2)]
159161
for i in range(1, len(xy) - 1):
160162
point = xy[i]
161163
angles = [

0 commit comments

Comments
 (0)