-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Error raising on unsorted dimensions for draw_rect/draw_rounded_rect #7217
Comments
So you are saying that from PIL import Image, ImageDraw
im = Image.new("RGB", (1, 1))
draw = ImageDraw.Draw(im)
draw.rounded_rectangle(((2, 2), (5, 10)), radius=3) fails with an error? When I try it with Pillow 9.5.0, it doesn't. If you try the example I just posted, does it fail for you? If it doesn't, and your code does, could you provide the exact code that you're using? |
Sorry for having you confused from PIL import Image, ImageDraw
im = Image.new("RGB", (1, 1))
draw = ImageDraw.Draw(im)
draw.rounded_rectangle(((2, 2), (9, 10)), radius=3) This leads to an error at line 382, in file -> ImageDraw.py , in rounded_rectangle The error I have reported, does not get reproduced when utilizing the value as 5, just like you have said. When reproduced with the fill parameter, I do get errors, but not for the reasons I assumed they would be for.. from PIL import Image, ImageDraw
im = Image.new("RGB", (1, 1))
draw = ImageDraw.Draw(im)
draw.rounded_rectangle(((2, 2), (9, 10)), radius=3, fill=(0, 151, 62))
File ImageDraw.py, line 383, in rounded_rectangle
self.draw.draw_rectangle((x0 + r + 1, y0, x1 - r - 1, y1), fill, 1)
ValueError: x1 must be greater than or equal to x0 With the same value 9 and fill parameter, this time the error is different and is the issue I am facing. |
Thanks. When I test your new code, I find that it has already been fixed by #7151. The fix will be part of Pillow 10, due to be released on July 1. |
Thankyou! That should resolve it |
With the change in #6978
There is a hidden error now raised due to radius argument for draw_rounded_rectangle
This is in reference to x0, x1 dimensions raising the ValueError: x1 must be greater than or equal to x0
Wherein, the passed dimensions are sorted but when sent to draw_rounded_rectangle, it utilises underlying code of:-
self.draw.draw_rectangle((x0 + r + 1, y0, x1 - r - 1, y1), fill, 1)
Dynamic code such as
draw_rounded_rectangle((2, 2), (2 + variable, 10), radius=3)
[variable is >=0]
Thus implicitly fail in certain cases where the variable's value is 4 or less, which explicitly is greater than x0.
The documentation only states for x1 >= x0 and y1 >= y0, which while satisfied will raise the error in the above case.
Question:
Is there an already known solution towards it, for example utilizing
x0 + variable + radius + 1
when passing x1's value to the function? Which does not seem very ideal and may cause certain changes to the image generation that I am unaware of.Can this be documented with a possible solution in such a case?
The text was updated successfully, but these errors were encountered: