Ich versuche, dicke Rechtecke auf ein Bild mit ImageDraw Module von PIL/Kissen zu zeichnen.Gibt es eine Möglichkeit, die Breite eines Rechtecks in PIL anzugeben?
Ich versuchte mit draw.rectangle([x1, y1, x2, y2], outline='yellow', width=3)
, aber es scheint nicht die Breite Parameter.
Ich kann emulieren, was ich mit einer Reihe von Zeilen tun möchte, aber ich frage mich, ob es eine richtige Art und Weise zu tun ist.
'''
coordinates = [x1, y1, x2, y2]
(x1, y1)
*--------------
| |
| |
| |
| |
| |
| |
--------------*
(x2, y2)
'''
def draw_rectangle(drawing, coordinates, color='yellow', width=3):
#top
line_coordinates = [coordinates[0], coordinates[1], coordinates[2], coordinates[1]]
drawing.line(line_coordinates, fill=color, width=width)
#left
line_coordinates = [coordinates[0], coordinates[1], coordinates[0], coordinates[3]]
drawing.line(line_coordinates, fill=color, width=width)
#right
line_coordinates = [coordinates[2], coordinates[1], coordinates[2], coordinates[3]]
drawing.line(line_coordinates, fill=color, width=width)
#bottom
line_coordinates = [coordinates[0], coordinates[3], coordinates[2], coordinates[3]]
drawing.line(line_coordinates, fill=color, width=width)