Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

find out length of a string in pixels python

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')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #find #length #string #pixels #python
ADD COMMENT
Topic
Name
8+7 =