Skip to content

TrueType fonts rendered from top pixel instead of top of font #285

@neruson

Description

@neruson

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')

test

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions