Skip to content

Commit 2f5687f

Browse files
authored
Merge pull request #5390 from radarhere/gif_missing_background
Use zero if GIF background color index is missing
2 parents 8498bf7 + 3cb2413 commit 2f5687f

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed
660 Bytes
Loading
950 Bytes
Loading

Tests/test_file_gif.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,3 +864,11 @@ def test_extents():
864864
assert im.size == (100, 100)
865865
im.seek(1)
866866
assert im.size == (150, 150)
867+
868+
869+
def test_missing_background():
870+
# The Global Color Table Flag isn't set, so there is no background color index,
871+
# but the disposal method is "Restore to background color"
872+
with Image.open("Tests/images/missing_background.gif") as im:
873+
im.seek(1)
874+
assert_image_equal_tofile(im, "Tests/images/missing_background_first_frame.gif")

src/PIL/GifImagePlugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ def _seek(self, frame):
270270

271271
Image._decompression_bomb_check(dispose_size)
272272
self.dispose = Image.core.fill(
273-
"P", dispose_size, self.info["background"]
273+
"P", dispose_size, self.info.get("background", 0)
274274
)
275275
else:
276276
# replace with previous contents
277277
if self.im:
278278
# only dispose the extent in this frame
279279
self.dispose = self._crop(self.im, self.dispose_extent)
280-
except (AttributeError, KeyError):
280+
except AttributeError:
281281
pass
282282

283283
if interlace is not None:

0 commit comments

Comments
 (0)