from PIL import ImageFont def get_pil_text_size(text, font_size, font_name): font = ImageFont.truetype(font_name, font_size) size = font.getsize(text) return size get_pil_text_size('Hello world', 12, 'times.ttf')