私はPIL/pillowのImageDraw Moduleを使ってイメージに太い四角形を描画しようとしています。PILに矩形の幅を指定する方法はありますか?
私はdraw.rectangle([x1, y1, x2, y2], outline='yellow', width=3)
を使用しようとしましたが、widthパラメータが好きではないようです。
私は、たくさんの行でやりたいことをエミュレートすることができますが、それを行う正しい方法があるかどうかは疑問でした。
'''
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)