diff --git a/Tests/images/dispose_bgnd_transparency.gif b/Tests/images/dispose_bgnd_transparency.gif new file mode 100644 index 000000000..7c626fe72 Binary files /dev/null and b/Tests/images/dispose_bgnd_transparency.gif differ diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 46e2b5ab2..985f8e52c 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -337,6 +337,13 @@ def test_dispose_background(): pass +def test_dispose_background_transparency(): + with Image.open("Tests/images/dispose_bgnd_transparency.gif") as img: + img.seek(2) + px = img.convert("RGBA").load() + assert px[35, 30][3] == 0 + + def test_transparent_dispose(): expected_colors = [(2, 1, 2), (0, 1, 0), (2, 1, 2)] with Image.open("Tests/images/transparent_dispose.gif") as img: diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index db6944267..128afc428 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -271,11 +271,9 @@ class GifImageFile(ImageFile.ImageFile): Image._decompression_bomb_check(dispose_size) # by convention, attempt to use transparency first - color = ( - frame_transparency - if frame_transparency is not None - else self.info.get("background", 0) - ) + color = self.info.get("transparency", frame_transparency) + if color is None: + color = self.info.get("background", 0) self.dispose = Image.core.fill("P", dispose_size, color) else: # replace with previous contents