From 68d0193a58c9d2057864fc18f7ba47cb0e3d266d Mon Sep 17 00:00:00 2001 From: Rabinandan Kishor Date: Tue, 15 Oct 2024 23:29:16 +0900 Subject: [PATCH] Update plots.py Replaced self.font.getsize(label) and self.font.getbbox(text)[2 --- utils/plots.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/plots.py b/utils/plots.py index fa49dc19d..3448b4175 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -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, @@ -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)