Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Tests/test_imagedraw2.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_ellipse(bbox: Coords) -> None:
# Arrange
im = Image.new("RGB", (W, H))
draw = ImageDraw2.Draw(im)
pen = ImageDraw2.Pen("blue", width=2)
pen = ImageDraw2.Pen("blue")
brush = ImageDraw2.Brush("green")

# Act
Expand Down Expand Up @@ -177,7 +177,7 @@ def test_polygon(points: Coords) -> None:
# Arrange
im = Image.new("RGB", (W, H))
draw = ImageDraw2.Draw(im)
pen = ImageDraw2.Pen("blue", width=2)
pen = ImageDraw2.Pen("blue")
brush = ImageDraw2.Brush("red")

# Act
Expand All @@ -192,7 +192,7 @@ def test_rectangle(bbox: Coords) -> None:
# Arrange
im = Image.new("RGB", (W, H))
draw = ImageDraw2.Draw(im)
pen = ImageDraw2.Pen("green", width=2)
pen = ImageDraw2.Pen("green")
brush = ImageDraw2.Brush("black")

# Act
Expand All @@ -202,6 +202,16 @@ def test_rectangle(bbox: Coords) -> None:
assert_image_equal_tofile(im, "Tests/images/imagedraw_rectangle.png")


@pytest.mark.parametrize("bbox", BBOX)
def test_rectangle_pen_width(bbox: Coords) -> None:
im = Image.new("RGB", (W, H))
draw = ImageDraw2.Draw(im)
pen = ImageDraw2.Pen("white", width=4)
draw.rectangle(bbox, pen)
assert im.getpixel((28, 28)) == WHITE
assert im.getpixel((50, 50)) == BLACK


def test_big_rectangle() -> None:
# Test drawing a rectangle bigger than the image
# Arrange
Expand Down
9 changes: 6 additions & 3 deletions src/PIL/ImageDraw2.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@


class Pen:
"""Stores an outline color and width."""
"""Stores an outline color and width.

:param color: The outline color.
:param width: The line width, in pixels.
"""

def __init__(self, color: str, width: int = 1, opacity: int = 255) -> None:
self.color = ImageColor.getrgb(color)
Expand Down Expand Up @@ -115,8 +119,7 @@ def render(
else:
kwargs.setdefault("fill", fill)
kwargs.setdefault("outline", outline)
if op == "line":
kwargs.setdefault("width", width)
kwargs.setdefault("width", width)
getattr(self.draw, op)(xy, **kwargs)

def settransform(self, offset: tuple[float, float]) -> None:
Expand Down
Loading