Skip to content

rounded_rectangle with radius > 50% and single corner #9560

@rysson

Description

@rysson

What did you do?

Use rounded_rectangle() with radius bigger than half of the size with single corner enabled.

What did you expect to happen?

Draw correct corner arc without extra pixels.

What actually happened?

Visible fill color outside of the rounded rectangle.

What are your OS, Python and Pillow versions?

  • OS: Linux (Debian Forky)
  • Python: 3.13.12
  • Pillow: 12.2.0
--------------------------------------------------------------------
Pillow 12.2.0
Python 3.13.12 (main, Feb  4 2026, 15:06:39) [GCC 15.2.0]
--------------------------------------------------------------------
Python executable is /home/user/work/kodi/koframes/.venv/bin/python3
Environment Python files loaded from /home/user/work/kodi/koframes/.venv
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /home/user/work/kodi/koframes/.venv/lib/python3.13/site-packages/PIL
Binary Pillow modules loaded from /home/user/work/kodi/koframes/.venv/lib/python3.13/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 12.2.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.14.3
--- LITTLECMS2 support ok, loaded 2.18
--- WEBP support ok, loaded 1.6.0
--- AVIF support ok, loaded 1.4.1
--- JPEG support ok, compiled for libjpeg-turbo 3.1.4.1
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.4
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1, compiled for zlib-ng 2.3.3
--- LIBTIFF support ok, loaded 4.7.1
--- RAQM (Bidirectional Text) support ok, loaded 0.10.3, fribidi 1.0.16, harfbuzz 13.2.1
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
from PIL import Image, ImageDraw

def run(radius, file):
    mask = Image.new("L", (100, 100), 0)
    draw = ImageDraw.Draw(mask)

    draw.rounded_rectangle((0, 0, *mask.size), radius=radius, fill=128, outline=255,
                           corners=(True, False, False, False))

    mask.save(file)

run(50, "ok.png")
run(53, "looks_ok.png")
run(54, "bug.png")
run(75, "bug75.png")

ok and looks_ok:
Image Image

Bug:
Image

Look at extra pixel the image top:
Image

Bigger radius makes more extra pixels (radius 75):
Image

Summary

I know radius bigger than 50% has no sense for two nearest corners (neighbors). But it seems have a sense for single (or diagonal) corners.
If you want to disable those radii please update doc and maybe limit radius to half of the size in the code.

CSS for compare

Single corner

div {
width: 100px;
height: 100px;
border-top-left-radius: 75px;
background: red;
}
Image

Diagonal

div {
border-top-left-radius: 75px;
border-botom-right-radius: 75px;
}
Image

Neighbors (limited to 50%)

div {
border-top-left-radius: 75px;
border-top-right-radius: 75px;
}
Image

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