diff --git a/Tests/images/missing_background.gif b/Tests/images/missing_background.gif new file mode 100644 index 000000000..550d68d81 Binary files /dev/null and b/Tests/images/missing_background.gif differ diff --git a/Tests/images/missing_background_first_frame.gif b/Tests/images/missing_background_first_frame.gif new file mode 100644 index 000000000..be2c95b99 Binary files /dev/null and b/Tests/images/missing_background_first_frame.gif differ diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 94fc95b05..6d92bde76 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -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") diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index 48685c883..3c4cb6187 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -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: