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

Accept float stroke widths #8369

Merged
merged 1 commit into from
Sep 12, 2024
Merged

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Sep 11, 2024

Resolves #8359

When instructing FreeType of the stroke width, we multiply the number of pixels by 64.

Pillow/src/_imagingft.c

Lines 951 to 953 in cb2a0c4

FT_Stroker_Set(
stroker,
(FT_Fixed)stroke_width * 64,

So there's no reason why stroke widths couldn't be more precise than an integer number of pixels, and instead going down to 1/64th of a pixel.

To demonstrate, here's a progression from no stroke to 1px stroke width.

from PIL import Image, ImageDraw, ImageFont

im = Image.new("RGB", (360, 120))
d = ImageDraw.Draw(im)
font = ImageFont.load_default(size=100)
d.text((5, 0), "A", font=font, fill="#f00")
d.text((75, 0), "A", font=font, fill="#f00", stroke_fill="#0f0", stroke_width=0.25)
d.text((145, 0), "A", font=font, fill="#f00", stroke_fill="#0f0", stroke_width=0.5)
d.text((215, 0), "A", font=font, fill="#f00", stroke_fill="#0f0", stroke_width=0.75)
d.text((285, 0), "A", font=font, fill="#f00", stroke_fill="#0f0", stroke_width=1)

im.save("out.png")

out

@hugovk hugovk merged commit 575f574 into python-pillow:main Sep 12, 2024
48 of 49 checks passed
@radarhere radarhere deleted the stroke_width_float branch September 12, 2024 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants