-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
The line height isn't being calculated correctly for ImageDraw's multiline_text() function [1]. It's making an assumption that a capital "A" is as large as the font can be. However, if I use the word "Apple" you'll notice that the "p" in word creates a different text size.
The issue
Current code
line_spacing = self.textsize('A', font=font)[1] + spacing>>> self.textsize('A', font=font)[1]
170
>>> self.textsize('APPLE', font=font)[1]
170
>>> self.textsize('Apple', font=font)[1]
244 // <-- problem
How the text correctly looks on the web
How the image is rendered via pillow (incorrect line height)
Proposed Change
import string
...
line_spacing = self.textsize(string.ascii_letters, font=font)[1] + spacingGets characters above and below the text baseline. Use every upper and lower letter in the alphabet since you'll notice in the font above, the lower case "l" is the character with the highest point.
When that change is made, you'll see the correct text height in the image:
[1] https://github.com/python-pillow/Pillow/blob/master/PIL/ImageDraw.py#L269


