Skip to content

Commit df10a72

Browse files
zewtradarhere
authored andcommitted
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.
1 parent 68b844d commit df10a72

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/PIL/GifImagePlugin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,16 @@ def _seek(self, frame):
286286
if self.palette:
287287
self.mode = "P"
288288

289+
def load_prepare(self):
290+
super(GifImageFile, self).load_prepare()
291+
292+
if self.__frame == 0:
293+
# On the first frame, clear the buffer. Use the transparency index
294+
# if we have one, otherwise use the background index.
295+
default_color = self.info.get("transparency",
296+
self.info.get("background", 0))
297+
self.im.paste(default_color, (0,0, self.size[0], self.size[1]))
298+
289299
def tell(self):
290300
return self.__frame
291301

0 commit comments

Comments
 (0)