Skip to content

ImageDraw.rounded_rectangle: wrong ValueError #8303

@SIR-X

Description

@SIR-X

There is a problem in ImageDraw.ImageDraw.rounded_rectangle. There is no problem in code's logic. I'll share the code & error.

Code:

from PIL import Image, ImageDraw

board = Image.new("RGBA", (1000, 1000))
draw = ImageDraw.Draw(board)

draw.rounded_rectangle((0, 0, 50 * 2, 500), 50, fill="white", corners=(True, False, False, True))

Error:

Traceback (most recent call last):
  File "...\file.py", line 60, in <module>
    draw.rounded_rectangle((0, 0, 50 * 2, 500), 50, "red", corners=(True, False, False, True))
  File "...\.venv\Lib\site-packages\PIL\ImageDraw.py", line 508, in rounded_rectangle
    self.draw.draw_rectangle((x0 + r + 1, y0, x1 - r - 1, y1), fill_ink, 1)
ValueError: x1 must be greater than or equal to x0

If I don't pass the corners, it will work. If I don't pass the fill, it will work either as well! But I want them both and I can't use them here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions