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

Stroke Text Tittles Not Working Correctly #8697

Closed
bradley-pearson6597 opened this issue Jan 16, 2025 · 2 comments · Fixed by #8701
Closed

Stroke Text Tittles Not Working Correctly #8697

bradley-pearson6597 opened this issue Jan 16, 2025 · 2 comments · Fixed by #8701
Labels

Comments

@bradley-pearson6597
Copy link

What did you do?

When trying to create a piece of text with a stroke fill the tittles on i and j do not look correct.

What did you expect to happen?

I would expect that the stroke would fill all the way to the edge of the inner fill for the tittles.

What actually happened?

The tittles on the i and j look like they have a thin outline around them rather than filling to the tittle.

What are your OS, Python and Pillow versions?

  • OS: Windows
  • Python 3.11:
  • Pillow: 10.3.0
Pillow 10.3.0
Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)]
Python executable is C:\Users\bradl\anaconda3\python.exe
System Python files loaded from C:\Users\bradl\anaconda3
--------------------------------------------------------------------
Python Pillow modules loaded from C:\Users\USER\anaconda3\Lib\site-packages\PIL
Binary Pillow modules loaded from C:\Users\USER\anaconda3\Lib\site-packages\PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.3.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.3.2
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.2
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1
--- LIBTIFF support ok, loaded 4.6.0
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
from PIL import Image, ImageDraw, ImageFont

# Create an image with a white background
width, height = 2000, 400
image = Image.new("RGB", (width, height), "white")

# Load a font
font_size = 100
font = ImageFont.load_default(font_size)

# Create a drawing context
draw = ImageDraw.Draw(image)

# Define text and positions
text = 'i j h o w'
text_position = (100, 100)  # Position of the text
stroke_width = 14  # Width of the stroke
stroke_fill = "black"  # Color of the stroke
text_fill = "blue"  # Color of the text

# Draw text with stroke
draw.text(
    text_position,
    text,
    font=font,
    fill=text_fill,
    stroke_width=stroke_width,
    stroke_fill=stroke_fill,
)

image.save("testing.png", dpi=(300, 300))

Image

@hugovk hugovk added the Fonts label Jan 16, 2025
@radarhere
Copy link
Member

Taking a look, the gap between the regular text and the stroked text is generated by FreeType. It's not unique to our default font - the same issue occurs with Times New Roman.ttf on my macOS machine.

I've contacted FreeType support to see if this is considered a bug.

@radarhere
Copy link
Member

We've received a response about how FreeType handles this - #8701 (comment)

The algorithms are rather complicated. I suspect the problem with the inside border arises when the stroker radius exceeds the stem width or the dot radius. The inside border is ill-defined in this case. I doubt this can be fixed. This could happen to the outside border too but much less frequently.

I've created #8701 to adjust Pillow to fix the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants