Skip to content

rounded_rectangle produces black vertical line in edge case #9383

@billythegoat356

Description

@billythegoat356
Image

What did you do?

Call rounded_rectangle with radius being equal to SIZE / 2 - 1

What did you expect to happen?

Round corners normally.

What actually happened?

Rounded corners AND drew black vertical line (see screenshots).

What are your OS, Python and Pillow versions?

  • OS: Linux
  • Python: 3.11.13
  • Pillow: 12.1.0
--------------------------------------------------------------------
Pillow 12.1.0
Python 3.11.13 (main, Jun  4 2025, 00:00:00) [GCC 15.1.1 20250521 (Red Hat 15.1.1-2)]
--------------------------------------------------------------------
Python executable is /home/marc/Desktop/code2/Hermes/.venv/bin/python3
Environment Python files loaded from /home/marc/Desktop/code2/Hermes/.venv
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /home/marc/Desktop/code2/Hermes/.venv/lib64/python3.11/site-packages/PIL
Binary Pillow modules loaded from /home/marc/Desktop/code2/Hermes/.venv/lib64/python3.11/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 12.1.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.14.1
--- LITTLECMS2 support ok, loaded 2.17
--- WEBP support ok, loaded 1.6.0
--- AVIF support ok, loaded 1.3.0
--- JPEG support ok, compiled for libjpeg-turbo 3.1.3
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.4
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1.zlib-ng, compiled for zlib-ng 2.3.2
--- LIBTIFF support ok, loaded 4.7.1
--- RAQM (Bidirectional Text) support ok, loaded 0.10.3, fribidi 1.0.16, harfbuzz 12.3.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
from PIL import Image, ImageDraw


size = 100

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

    draw.rounded_rectangle((0, 0, *mask.size), radius=radius, fill=255)

    mask.save(file)

run(48, "ok.png")
run(50, "ok2.png")
run(49, "bug.png")

I found that whenever the radius is exactly equal to SIZE / 2 - 1, a black vertical line is produced (see image).
In my example, it happens when radius is 49. It does not happen when it is 50, or 48.
It also happens with any image size, as long as the radius is equal to SIZE / 2 - 1.

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