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 radarhere force-pushed the rounded_rectangle branch from dfc4265 to 16087b2 Jan 15, 2021
@radarhere radarhere force-pushed the rounded_rectangle branch 4 times, most recently from 1d17c8d to 16fe3a9 Jan 16, 2021
@radarhere
Copy link
Member Author

@radarhere radarhere commented Jan 18, 2021

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.

@radarhere radarhere force-pushed the rounded_rectangle branch from 16fe3a9 to e340319 Feb 17, 2021
@glenn-jocher
Copy link

@glenn-jocher glenn-jocher commented Feb 18, 2021

+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.

@radarhere radarhere force-pushed the rounded_rectangle branch from e340319 to d1757e3 Feb 21, 2021
@hugovk
Copy link
Member

@hugovk 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

@hugovk hugovk Mar 7, 2021

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

@radarhere radarhere Mar 8, 2021

Thanks, done.

Copy link
Member

@hugovk hugovk Mar 8, 2021

Did this get missed in the rebase?

Copy link
Member Author

@radarhere radarhere Mar 8, 2021

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

@hugovk hugovk Mar 8, 2021

Ah yes, refresh sorted it, thanks!

image

@radarhere radarhere force-pushed the rounded_rectangle branch from c8dec79 to 9ce3eba Mar 8, 2021
@radarhere
Copy link
Member Author

@radarhere radarhere commented Mar 8, 2021

Ok, I've added release notes.

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

Successfully merging this pull request may close these issues.

3 participants