From aeba819f11646e7a3202f6d870c637855bfdf127 Mon Sep 17 00:00:00 2001 From: tony Date: Tue, 25 Jun 2024 11:33:01 -0400 Subject: [PATCH] Update text bounding box to work with PIL>9.5 --- src/pyvision/types/img.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pyvision/types/img.py b/src/pyvision/types/img.py index cd5b978..52dbe11 100644 --- a/src/pyvision/types/img.py +++ b/src/pyvision/types/img.py @@ -625,10 +625,16 @@ def annotateLabel(self,point,label,color='red',mark=False, font=None, background font = ImageFont.load_default() elif isinstance(font,int): font = ImageFont.truetype(pv.FONT_ARIAL, font) - + # Compute the size - tw,th = draw.textsize(label, font=font) - + # Pillow deprecated textsize in 9.5.0 and replaced it with textbbox + if hasattr(draw, 'textbbox'): + left, top, right, bottom = draw.textbbox(xy=(0, 0), text=label, font=font) + tw = right - left + th = bottom - top + elif hasattr(draw, 'textsize'): + tw, th = draw.textsize(label, font=font) + # Select the position relative to the point if mark in [True, 'right']: textpt = pv.Point(point.X()+5,point.Y()-th/2)