Merge pull request #5390 from radarhere/gif_missing_background

Use zero if GIF background color index is missing
This commit is contained in:
Hugo van Kemenade 2021-04-15 11:57:31 +03:00 committed by GitHub
commit 2f5687f886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 660 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 950 B

View File

@ -864,3 +864,11 @@ def test_extents():
assert im.size == (100, 100)
im.seek(1)
assert im.size == (150, 150)
def test_missing_background():
# The Global Color Table Flag isn't set, so there is no background color index,
# but the disposal method is "Restore to background color"
with Image.open("Tests/images/missing_background.gif") as im:
im.seek(1)
assert_image_equal_tofile(im, "Tests/images/missing_background_first_frame.gif")

View File

@ -270,14 +270,14 @@ class GifImageFile(ImageFile.ImageFile):
Image._decompression_bomb_check(dispose_size)
self.dispose = Image.core.fill(
"P", dispose_size, self.info["background"]
"P", dispose_size, self.info.get("background", 0)
)
else:
# replace with previous contents
if self.im:
# only dispose the extent in this frame
self.dispose = self._crop(self.im, self.dispose_extent)
except (AttributeError, KeyError):
except AttributeError:
pass
if interlace is not None: