From e29a7d8a94ab88eccae91a0b8903ff170ec03bb2 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 26 Jun 2021 00:55:31 +1000 Subject: [PATCH] Replace with transparency if available for disposal method 2 --- src/PIL/GifImagePlugin.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index 658bee214..2f988ff43 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -269,9 +269,14 @@ class GifImageFile(ImageFile.ImageFile): dispose_size = (x1 - x0, y1 - y0) Image._decompression_bomb_check(dispose_size) - self.dispose = Image.core.fill( - "P", dispose_size, self.info.get("background", 0) + + # by convention, attempt to use transparency first + color = ( + frame_transparency + if frame_transparency is not None + else self.info.get("background", 0) ) + self.dispose = Image.core.fill("P", dispose_size, color) else: # replace with previous contents if self.im: