-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Description
As of this commit in Pillow 2.1.0, TrueType fonts are drawn from the top pixel down, instead of from the max height of the font. This means that lines containing only half-height lowercase characters, for example, are rendered at a different height than full-height characters. Because of this, it's basically impossible to evenly space text over multiple lines.
from PIL import Image, ImageDraw, ImageFont
im = Image.new(mode='RGB', size=(150,100))
font = ImageFont.truetype("Arial.ttf", 16, encoding='unic')
draw = ImageDraw.Draw(im)
line_spacing = draw.textsize('A', font=font)[1] + 5
lines = ['hey you', 'you are awesome', 'this looks awkward']
y = 0
for line in lines:
draw.text((0, y), line, font=font)
y += line_spacing
im.save('test.png', 'PNG')
Metadata
Metadata
Assignees
Labels
No labels
