Fixed im.frombytes() for images with a zero dimension

This commit is contained in:
Andrew Murray 2023-10-25 08:52:26 +11:00
parent 5071692039
commit 91f115bead
2 changed files with 6 additions and 0 deletions

View File

@ -910,6 +910,9 @@ class TestImage:
def test_zero_frombytes(self, size): def test_zero_frombytes(self, size):
Image.frombytes("RGB", size, b"") Image.frombytes("RGB", size, b"")
im = Image.new("RGB", size)
im.frombytes(b"")
def test_has_transparency_data(self): def test_has_transparency_data(self):
for mode in ("1", "L", "P", "RGB"): for mode in ("1", "L", "P", "RGB"):
im = Image.new(mode, (1, 1)) im = Image.new(mode, (1, 1))

View File

@ -791,6 +791,9 @@ class Image:
but loads data into this image instead of creating a new image object. but loads data into this image instead of creating a new image object.
""" """
if self.width == 0 or self.height == 0:
return
# may pass tuple instead of argument list # may pass tuple instead of argument list
if len(args) == 1 and isinstance(args[0], tuple): if len(args) == 1 and isinstance(args[0], tuple):
args = args[0] args = args[0]