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

Added text stroking #3978

Merged
merged 2 commits into from
Sep 6, 2019
Merged

Added text stroking #3978

merged 2 commits into from
Sep 6, 2019

Conversation

radarhere
Copy link
Member

Resolves #2209. Replacement for #2224

Adds strokeWidth and strokeFill arguments, such that -

from PIL import Image, ImageDraw, ImageFont

font = ImageFont.truetype("Tests/fonts/FreeMono.ttf", 40)
font.getsize_multiline("A", strokeWidth=2)
font.getsize("ABC\nAaaa", strokeWidth=2)

im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
draw.textsize("A", font, strokeWidth=2)
draw.multiline_textsize("ABC\nAaaa", font, strokeWidth=2)
draw.text((10, 10), "A", "#f00", font, strokeWidth=2, strokeFill="#0f0")
draw.multiline_text((10, 10), "A\nB", "#f00", font, strokeWidth=2, strokeFill="#0f0")

Uses FreeType's stroking. See https://www.freetype.org/freetype2/docs/reference/ft2-glyph_stroker.html for more information, and part of https://www.freetype.org/freetype2/docs/tutorial/example2.cpp for example code.

Also renames a FT_GlyphSlot variable from 'glyph' to 'glyphSlot'.

src/PIL/ImageDraw.py Outdated Show resolved Hide resolved
@radarhere radarhere force-pushed the stroke branch 3 times, most recently from bd71070 to ac613da Compare July 19, 2019 10:26
docs/reference/ImageDraw.rst Outdated Show resolved Hide resolved

.. versionadded:: 6.2.0

.. py:method:: PIL.ImageDraw.ImageDraw.multiline_textsize(text, font=None, spacing=4, direction=None, features=None, language=None, strokeWidth=0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And update the py:methods for the other updated ones.

src/PIL/ImageDraw.py Outdated Show resolved Hide resolved
src/PIL/ImageDraw.py Outdated Show resolved Hide resolved
src/_imagingft.c Outdated Show resolved Hide resolved
src/_imagingft.c Outdated Show resolved Hide resolved
src/_imagingft.c Outdated Show resolved Hide resolved
src/_imagingft.c Outdated Show resolved Hide resolved
src/_imagingft.c Outdated Show resolved Hide resolved
src/_imagingft.c Outdated Show resolved Hide resolved
@radarhere radarhere force-pushed the stroke branch 2 times, most recently from bdc7068 to 4013dbb Compare July 28, 2019 11:58
Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a naming thing, then we're good to merge. Thanks!

src/PIL/ImageDraw.py Outdated Show resolved Hide resolved
src/PIL/ImageDraw.py Outdated Show resolved Hide resolved
src/PIL/ImageDraw.py Outdated Show resolved Hide resolved
src/PIL/ImageDraw.py Outdated Show resolved Hide resolved
Co-Authored-By: Hugo van Kemenade <hugovk@users.noreply.github.com>
@radarhere radarhere merged commit da39d40 into python-pillow:master Sep 6, 2019
@radarhere radarhere deleted the stroke branch September 6, 2019 09:15
@nulano nulano mentioned this pull request Sep 30, 2019
19 tasks
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.

ImageFont/ImageDraw should support text stroking
3 participants