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

@radarhere radarhere commented Jul 19, 2019

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 Jul 19, 2019
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

@hugovk hugovk Jul 24, 2019

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 Jul 28, 2019
hugovk
hugovk approved these changes Sep 5, 2019
Copy link
Member

@hugovk hugovk left a comment

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
16 checks passed
@radarhere radarhere deleted the stroke branch Sep 6, 2019
@radarhere radarhere mentioned this pull request Sep 14, 2019
@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
Linked issues

Successfully merging this pull request may close these issues.

3 participants