Skip to content
Open
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
10 changes: 10 additions & 0 deletions Tests/test_imageops.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ def test_contain_round() -> None:
assert new_im.height == 5


def test_contain_zero() -> None:
im = Image.new("1", (1, 10))
new_im = ImageOps.contain(im, (5, 5))
assert new_im.width == 0

im = Image.new("1", (10, 1))
new_im = ImageOps.contain(im, (5, 5))
assert new_im.height == 0


@pytest.mark.parametrize(
"image_name, expected_size",
(
Expand Down
2 changes: 2 additions & 0 deletions src/PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ def contain(
new_width = round(image.width / image.height * size[1])
if new_width != size[0]:
size = (new_width, size[1])
if min(size) == 0:
return Image.new(image.mode, size)
return image.resize(size, resample=method)


Expand Down
Loading