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.
This commit is contained in:
Glenn Maynard 2018-10-23 23:09:13 -05:00 committed by Andrew Murray
parent 68b844de74
commit df10a72000

View File

@ -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