Skip to content

Issue with Font Drawing and dimensions #376

@arusahni

Description

@arusahni

I just upgraded to Pillow 2.2.1 (from 2.1.0) and font drawing in my program is broken.

On 2.1.0, a draw operation like:

image = Image.open(self.image_path)
self.size = image.size   # 640x480, in my case
top_dimensions = self.__get_text_dimensions(self.top_text, top_font_size)  # (156, 25)
top_position = (self.size[0] - 5 - top_dimensions[0], 5)

draw = ImageDraw.Draw(image)
self.__draw_image(draw, self.top_text, top_font_size, top_position)
font = ImageFont.truetype(self.font, top_font_size)
stroke_width = 3
for x_off in range(-stroke_width, stroke_width + 1):
    for y_off in range(-stroke_width, stroke_width + 1):
        draw.text((top_position[0] + x_off, top_position[1] + y_off), self.top_text, STROKE_COLOR, font=font)
draw.text(top_position, self.top_text, TEXT_COLOR, font=font)

Would draw text with a 5px offset from the top. The draw operations in the nested for loops effectively add an outline to the text. After upgrading to 2.2.1, though, the offsets are different, and all text appears to be shifted down by about 7-10 pixels. I checked the changelogs, and don't see anything that directly addresses this behavior.

I can provide the full image drawing code, if needed.

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