Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Font Drawing and dimensions #376

Closed
arusahni opened this issue Oct 13, 2013 · 2 comments
Closed

Issue with Font Drawing and dimensions #376

arusahni opened this issue Oct 13, 2013 · 2 comments

Comments

@arusahni
Copy link

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.

@wiredfool
Copy link
Member

It could have been #333, which fixed #285.

@arusahni
Copy link
Author

Looks like that's it! I'll have to update my code for the now-standard behavior. Thanks!

radarhere pushed a commit to radarhere/Pillow that referenced this issue Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants