Draw Exact fontsize in pixels in Pillow

Viewed 27

For drawing a text with a custom font on a image using pillow we use truetype function. But when I use that and I specify the fontsize, the text which is drawn is not really the exact fontsize which it should've been.

For eg:

 
draw = ImageDraw.Draw(image) 
  
# specified  size
font = ImageFont.truetype(r'devangiri.ttf', 20) 
  
text = 'SOMEWORDS'
  
# drawing text size
draw.text((5, 5), text, font = font)

When I cross check the output image, and calculate the font size, it is not really equal to 20px which it should've been. As font size is merely height of text, when I calculate that height, both are not same by big values.

How to calculate correct font size to write in truetype ?

0 Answers
Related