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
Function for Rounded Rectangle #4765
Comments
So to be clear, you can already achieve the desired outcome with Pillow, you're just suggesting that this code become a part of Pillow? |
Yeah I think there will be several ppl. which might use such function. I also found those functions in other image libraries (other languages) so might be worth considering to implement. My implementation also won't be the best, so you or other ppl. find ways to improve it. |
I don't understand what you were trying to achieve with the create_rounded_rectangle_mask((200, 100), 30, 255).show() But 127 and 0 just don't seem like they would be helpful. create_rounded_rectangle_mask((200, 100), 30, 127).show() create_rounded_rectangle_mask((200, 100), 30, 0).show() |
I've created PR #5208. See what you think |
@radarhere Am not fully aware of how to use this value right. I encountered an issue if I create a rounded rectangle with alpha lower than 255. This happens when you not adjusting alpha: My version of just using the same alpha as the image is imperfect too. If you zoom in, you'll see that the corners got a different alpha. |
Ok, sure. Using my PR, you should be able to just set from PIL import Image, ImageDraw
im = Image.new("RGB", (500, 100), (0, 0, 100))
draw = ImageDraw.Draw(im, "RGBA")
draw.rounded_rectangle((20, 20, 480, 80), 30, fill=(255,255,255,50))
draw.rounded_rectangle((20, 20, 280, 80), 30, fill=(255,0,0,100))
im.show() |
@radarhere Sounds great! Looking forward to use this function in a future version. |
Your idea of using antialiasing to create a smoother result doesn't purely apply to rounded rectangles - it might equally be applied to other shapes. While I acknowledge that it might be useful, I'm reluctant to officially endorse it as a strategy - if there is a need for it, my personal feeling is that it is more of a workaround than a proper solution. Feel free to create a PR yourself, or if you'd like to continue talking about smoothing, would you be able to open a new issue? It would be nice to keep this issue specifically about rounded rectangles. |
Feature Request
I got a feature request for the
ImageDraw
module.For more modern design, it's very useful to create a rectangle with rounded corners. Currently, it requires a higher effort to create such a rounded rectangle.
My Code:
This mask will be used to paste with a normal rectangle.
The text was updated successfully, but these errors were encountered: