Add a feature to ImageDraw.text() to stroke text#2224
Add a feature to ImageDraw.text() to stroke text#2224Irishsmurf wants to merge 2 commits intopython-pillow:masterfrom Irishsmurf:dev
Conversation
hugovk
left a comment
There was a problem hiding this comment.
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
PIL/ImageDraw.py
Outdated
|
|
||
| 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.
Put outline at the end, because changing the order of parameters can break existing user code.
Tests/test_imagefont.py
Outdated
| 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.
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.
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.
PIL/ImageDraw.py
Outdated
|
|
||
| spacing, align, outline) | ||
| ink, fill = self._getink(fill) | ||
| print("Outline: %s" % outline) |
|
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:
outlineargument 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.