-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 "corners" argument to ImageDraw rounded_rectangle() #6954
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
@@ -296,15 +296,14 @@ def rectangle(self, xy, fill=None, outline=None, width=1): | |||
self.draw.draw_rectangle(xy, ink, 0, width) | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
corners
argument 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.