Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions utils/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def box_label(self, box, label='', color=(128, 128, 128), txt_color=(255, 255, 2
if self.pil or not is_ascii(label):
self.draw.rectangle(box, width=self.lw, outline=color) # box
if label:
w, h = self.font.getsize(label) # text width, height
w, h = self.font.getbbox(label)[2:4] # bounding box, get width and height
outside = box[1] - h >= 0 # label fits outside box
self.draw.rectangle(
(box[0], box[1] - h if outside else box[1], box[0] + w + 1,
Expand Down Expand Up @@ -162,7 +162,7 @@ def rectangle(self, xy, fill=None, outline=None, width=1):
def text(self, xy, text, txt_color=(255, 255, 255), anchor='top'):
# Add text to image (PIL-only)
if anchor == 'bottom': # start y from font bottom
w, h = self.font.getsize(text) # text width, height
w, h = self.font.getbbox(text)[2:4] # get bounding box, extract width and height
xy[1] += 1 - h
self.draw.text(xy, text, fill=txt_color, font=self.font)

Expand Down