Skip to content

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