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
Add a feature to ImageDraw.text() to stroke text #2224
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also update docs:
https://github.com/python-pillow/Pillow/blob/master/docs/reference/ImageDraw.rst
Should this also be in a 3.5.0 release note?
https://github.com/python-pillow/Pillow/tree/master/docs/releasenotes
self.draw.draw_bitmap(xy, mask, ink) | ||
|
||
def multiline_text(self, xy, text, fill=None, font=None, anchor=None, | ||
spacing=4, align="left"): | ||
outline=None, spacing=4, align="left"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put outline
at the end, because changing the order of parameters can break existing user code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -164,7 +175,7 @@ def test_render_multiline_text(self): | |||
# to multiline_text() | |||
draw.text((0, 0), TEST_TEXT, fill=None, font=ttf, anchor=None, | |||
spacing=4, align="left") | |||
draw.text((0, 0), TEST_TEXT, None, ttf, None, 4, "left") | |||
draw.text((0, 0), TEST_TEXT, None, ttf, None, None, 4, "left") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an example of existing user code that is broken by changing the order of parameters. This change shouldn't be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
I've gone ahead and refactored the ImageDraw.text() method signature to no longer take in **kwargs which I believe will allow for greater flexibility in future.
Other than passing the Align and Spacing args to multiline_text, I don't believe it's using anything else (Atleast it's not documented)
Moved to explicitly declaring the keyword arguments
This change adds an additional method argument to the draw() method which draws the text in black, before drawing it in the color selected in the fill parameter. Additionally due to the positional requirements enforced on the method by using **kwargs, move to using an explicit signature with default values. * Helps improve readability * Allows for easier modification later.
ink, fill = self._getink(fill) | ||
print("Outline: %s" % outline) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove print
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops.
Addressed.
I'm not necessarily sold either way on this question, but have you considered updating |
I think that this is the wrong approach. At the very least, it's not adjusting the spacing due to the wider letters and the stroke is fixed at one pixel. The right approach is going to take hooking into the freetype layer using FT_Stroker, as seen here: http://stackoverflow.com/a/28078293 . |
I've created PR #3978 instead. |
Fixes #2209 and #1907
Changes proposed in this pull request:
outline
argument to ImageDraw.text() & ImageDraw.multiline_text()This change adds an additional method argument to the draw() method
which draws the text in black, before drawing it in the color selected
in the fill parameter.
ImageDraw.text((5, 5), caption, BLACK, outline='White', font=FONT)
Alternatively - I can do this is to break out ImageDraw.text and ImageDraw.stroke_text().
Feedback welcome.