From df10a72000cb35eb9d9043c98478a32759d42a3d Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 23 Oct 2018 23:09:13 -0500 Subject: [PATCH] GIF: Clear the buffer to the correct initial color before decoding frame 0. This ensures that transparent pixels in the first frame data clear to transparency and not to some previously decoded frame. --- src/PIL/GifImagePlugin.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index f8cacffbd..f2857ac36 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -286,6 +286,16 @@ class GifImageFile(ImageFile.ImageFile): if self.palette: self.mode = "P" + def load_prepare(self): + super(GifImageFile, self).load_prepare() + + if self.__frame == 0: + # On the first frame, clear the buffer. Use the transparency index + # if we have one, otherwise use the background index. + default_color = self.info.get("transparency", + self.info.get("background", 0)) + self.im.paste(default_color, (0,0, self.size[0], self.size[1])) + def tell(self): return self.__frame