What did you do?
I recently updated one of my programs from 9.4 to 9.5 and got this new ValueError when drawing rounded rectangles on an image.
After some trials and error, I think the bug only happens when the rectangle height equals 1 + 2*radius. I'm not 200% confident about that, but that's all I got so far.
The exact lines causing the error are
|
left = [x0, y0, x0 + r, y1] |
|
if corners[0]: |
|
left[1] += r + 1 |
|
if corners[3]: |
|
left[3] -= r + 1 |
|
self.draw.draw_rectangle(left, fill, 1) |
What did you expect to happen?
Well, PIL should be able to correctly calculate positions and draw my rounded corners.
What actually happened?
Traceback (most recent call last):
File "/.../test.py", line 17, in <module>
main()
File "/.../test.py", line 14, in main
draw.rounded_rectangle(coordinates, radius=3, fill=(0, 0, 0))
File "/.../env/lib/python3.9/site-packages/PIL/ImageDraw.py", line 385, in rounded_rectangle
self.draw.draw_rectangle(left, fill, 1)
ValueError: y1 must be greater than or equal to y0
What are your OS, Python and Pillow versions?
- OS: macOS 13.3.1
- Python: 3.9.16
- Pillow: 9.5.0
from PIL import Image, ImageDraw
def main():
# get a 1021x340 image
img = Image.new('RGB', (20, 20), color=(255, 255, 255))
# draw a rounded rectangle on it
draw = ImageDraw.Draw(img)
coordinates = (
(5, 0),
(15, 7)
)
# here's the bug:
# on ImageDraw.py line 383, y1 from "left" will be 1px less than y0
draw.rounded_rectangle(coordinates, radius=3, fill=(0, 0, 0))
if __name__ == '__main__':
main()
What did you do?
I recently updated one of my programs from 9.4 to 9.5 and got this new ValueError when drawing rounded rectangles on an image.
After some trials and error, I think the bug only happens when the rectangle height equals
1 + 2*radius. I'm not 200% confident about that, but that's all I got so far.The exact lines causing the error are
Pillow/src/PIL/ImageDraw.py
Lines 378 to 383 in 2a274a4
What did you expect to happen?
Well, PIL should be able to correctly calculate positions and draw my rounded corners.
What actually happened?
What are your OS, Python and Pillow versions?