Merge pull request #5938 from radarhere/zero

Return an empty bytestring from tobytes() for an empty image
This commit is contained in:
Hugo van Kemenade 2022-01-07 08:34:50 +02:00 committed by GitHub
commit 5908ccc5ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)