From b5806c7e15d1dcb5808714fd0018e223d1d97039 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 23 Oct 2018 23:09:47 -0500 Subject: [PATCH] GIF: Clear to transparency rather than background if available. Background dispose should prefer the transparency color over the background color, if there is one. This matches other decoders and makes transparent_dispose.gif decode correctly. --- src/PIL/GifImagePlugin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index f2857ac36..ecf4c2be5 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -258,9 +258,10 @@ class GifImageFile(ImageFile.ImageFile): # do not dispose or none specified self.dispose = None elif self.disposal_method == 2: - # replace with background colour - self.dispose = Image.core.fill("P", self.size, - self.info["background"]) + # replace with transparency if there is one, otherwise + # background colour + bg = info.get("transparency", self.info["background"]) + self.dispose = Image.core.fill("P", self.size, bg) else: # replace with previous contents if self.im: