Files
Roster/utils/text_metrics.py
2025-06-28 01:12:46 -05:00

8 lines
234 B
Python

from PIL import ImageFont
def get_text_width(text, font_path, font_size):
font = ImageFont.truetype(font_path, font_size)
bbox = font.getbbox(text) # (left, top, right, bottom)
width = bbox[2] - bbox[0]
return width