I'm trying to find the size, in points, of some text using Pillow in python. As I understand it, font sizes in points correspond to real physical inches on a target display or surface, with 72 points per inch. When I use Pillow's textsize
method, I can find the size in pixels of some text rendered at a given font size (in points), but don't know how to get back to a coordinate system based in inches, because I don't have (and can't set) the pixel density of the image:
from PIL import Image, ImageFont, ImageDraw
image = Image.new('RGBA', (400, 300), (255, 255, 255))
font = ImageFont.truetype('/Library/Fonts/Arial.ttf', 16)
image.info['dpi'] = 100
print( ImageDraw.Draw(image).textsize('Loreum ipsum', font=font) )
image.info['dpi'] = 1000
print( ImageDraw.Draw(image).textsize('Loreum ipsum', font=font) )
will print
(101, 18)
(101, 18)
How do I get the size in points of the given text?