I have a problem with the PIL ImageDraw module, in particular with the Draw.textsize method. It is assumed that this method accepts a string and a font and returns the width and height that the string will occupy when rendering in this font. It seems he has a lower bound on the height that he returns, though: I cannot convince him to return anything below 43 . Here is an example ( link ) to show what I'm looking at (bounding boxes drawn around text based on the returned width and height), and here is the code that created it:
from PIL import Image, ImageDraw, ImageFont
As soon as the font size reaches size 38, the bounding rectangle is stretched to fit it correctly, but before that it set static 43 . The question is, does anyone know why ImageDraw behaves this way, and does anyone know how to fix it? I am currently working on a problem by setting:
width = min(width, fontsize+1)
... but this is obviously not the most reliable solution that has ever been developed.
Henry Keiter
source share