Skip to content

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 radarhere force-pushed the rounded_rectangle branch 4 times, most recently from 1d17c8d to 16fe3a9 Compare January 16, 2021 11:07
@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 radarhere force-pushed the rounded_rectangle branch from c8dec79 to 9ce3eba Compare March 8, 2021 08:54
@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