Skip to content

Added text stroking#3978

Merged
radarhere merged 2 commits intopython-pillow:masterfrom
radarhere:stroke
Sep 6, 2019
Merged

Added text stroking#3978
radarhere merged 2 commits intopython-pillow:masterfrom
radarhere:stroke

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'.

@radarhere radarhere force-pushed the stroke branch 3 times, most recently from bd71070 to ac613da Compare July 19, 2019 10:26

.. 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.

@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!

Co-Authored-By: Hugo van Kemenade <[email protected]>
@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