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 ImageDraw rounded_rectangle method #5208

Merged
merged 3 commits into from Mar 8, 2021

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Jan 15, 2021

Resolves #4765 by adding rounded_rectangle().

Like rectangle(),

def rectangle(self, xy, fill=None, outline=None, width=1):

except with a radius argument

def rounded_rectangle(self, xy, radius=0, fill=None, outline=None, width=1):

In this implementation, I limit the radius of the corners so that it is not greater than half of the width or the height - so a rounded rectangle might be a circle, but not another ellipse.

@radarhere
Copy link
Member Author

I've added a commit to only draw each pixel once, so that translucent colours can be used without creating an inconsistent opacity - see #5183 and #4333 for similar changes.

@glenn-jocher
Copy link

+1 for this PR, I like the idea. If it's not too slow I think we will use it in our YOLOv5 repo, as then we can achieve uniformity with our iOS app rectangles with rounded corners.

@hugovk
Copy link
Member

hugovk commented Mar 7, 2021

Please could you add this to the release notes?

:param fill: Color to use for the fill.
:param width: The line width, in pixels.

.. versionadded:: 8.2.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this directive is applied to the width param:

image

Shall we move it up, similar to ImageDraw.textlength, to apply to the whole method?

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this get missed in the rebase?

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 don't believe so. I suspect if you refresh https://pillow--5208.org.readthedocs.build/en/5208/reference/ImageDraw.html again, it will work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, refresh sorted it, thanks!

image

@radarhere
Copy link
Member Author

Ok, I've added release notes.

@hugovk hugovk merged commit 02ed076 into python-pillow:master Mar 8, 2021
@radarhere radarhere deleted the rounded_rectangle branch March 8, 2021 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function for Rounded Rectangle
3 participants