Added "corners" argument to ImageDraw rounded_rectangle()#6954
Added "corners" argument to ImageDraw rounded_rectangle()#6954hugovk merged 2 commits intopython-pillow:mainfrom
Conversation
|
Re: https://understandlegacycode.com/blog/what-is-wrong-with-boolean-parameters/ Rather than something like: rounded_rectangle((10, 20, 190, 180), 30, (True, False, True, True))Would it be better if we made rounded_rectangle((10, 20, 190, 180), 30, rounded=(True, False, True, True)) |
|
Ok, I've pushed a commit to only allow >>> draw.rounded_rectangle((10, 20, 190, 180), 30, "red", "green", 5, (True, True, True, True))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: rounded_rectangle() takes from 2 to 6 positional arguments but 7 were given
>>> draw.rounded_rectangle((10, 20, 190, 180), 30, "red", "green", 5, corners=(True, True, True, True))
>>> |
src/PIL/ImageDraw.py
Outdated
|
|
||
| def rounded_rectangle( | ||
| self, xy, radius=0, fill=None, outline=None, width=1, corners=None | ||
| self, xy, radius=0, fill=None, outline=None, width=1, **kwargs |
There was a problem hiding this comment.
Or something like this for more transparency? Better for help(rounded_rectangle) and so on.
| self, xy, radius=0, fill=None, outline=None, width=1, **kwargs | |
| self, xy, radius=0, fill=None, outline=None, width=1, *, corners=None |
Or even this?
| self, xy, radius=0, fill=None, outline=None, width=1, **kwargs | |
| self, xy, radius=0, fill=None, outline=None, width=1, *, corners=(True, True, True, True) |
(And update/delete the below to match.)
There was a problem hiding this comment.
I think corners=(True, True, True, True) is best. But what would the ordering be? Top left, top right, bottom right, bottom left (clock wise)?
There was a problem hiding this comment.
I've updated the commit to use the first suggestion.
As for the ordering, yes, that is the ordering I've used. It mirrors the ordering in CSS for border-radius.
Resolves #6953, by adding a
cornersargument toImageDraw.rounded_rectangle- a tuple of booleans for whether or not to round each corner, going clockwise, starting with top left and ending with bottom left.