Skip to content

Commit

Permalink
Merge pull request #7 from tonygallen/master
Browse files Browse the repository at this point in the history
Update text bounding box to work with PIL>9.5
  • Loading branch information
joelb92 authored Jun 26, 2024
2 parents 555c5d0 + aeba819 commit f025248
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/pyvision/types/img.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f025248

Please sign in to comment.