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
5 changes: 5 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,11 @@ def test_exif_load_from_fp(self):
34665: 196,
}

@pytest.mark.parametrize("size", ((1, 0), (0, 1), (0, 0)))
def test_zero_tobytes(self, size):
im = Image.new("RGB", size)
assert im.tobytes() == b""

def test_categories_deprecation(self):
with pytest.warns(DeprecationWarning):
assert hopper().category == 0
Expand Down
3 changes: 3 additions & 0 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ def tobytes(self, encoder_name="raw", *args):

self.load()

if self.width == 0 or self.height == 0:
return b""

# unpack data
e = _getencoder(self.mode, encoder_name, args)
e.setimage(self.im)
Expand Down