Skip to content
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

Merged
merged 2 commits into from
Feb 26, 2023

Conversation

radarhere
Copy link
Member

Resolves #6953, by adding a corners argument to ImageDraw.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.

@hugovk
Copy link
Member

hugovk commented Feb 16, 2023

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 corners a required keyword argument?

rounded_rectangle((10, 20, 190, 180), 30, rounded=(True, False, True, True))

@radarhere
Copy link
Member Author

Ok, I've pushed a commit to only allow corners to be used as a keyword argument.

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

@@ -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
Copy link
Member

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.

Suggested change
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?

Suggested change
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.)

Copy link

@ChrisMGeo ChrisMGeo Feb 16, 2023

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)?

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a corners parameter for ImageDraw.rounded_rectangle?
3 participants