Return an empty bytestring from tobytes() for an empty image

This commit is contained in:
Andrew Murray 2022-01-07 16:29:38 +11:00
parent 0648692b2c
commit b5160591bc
2 changed files with 8 additions and 0 deletions

View File

@ -786,6 +786,11 @@ class TestImage:
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

View File

@ -716,6 +716,9 @@ class Image:
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)