Skip to content

Commit bb5a34f

Browse files
authored
Merge pull request #5391 from radarhere/gif_disposal
Treat previous contents of first GIF frame as transparent
2 parents cfc9ad4 + a47072b commit bb5a34f

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed
530 Bytes
Loading
1 KB
Loading

Tests/test_file_gif.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@ def test_dispose_previous():
341341
pass
342342

343343

344+
def test_dispose_previous_first_frame():
345+
with Image.open("Tests/images/dispose_prev_first_frame.gif") as im:
346+
im.seek(1)
347+
assert_image_equal_tofile(
348+
im, "Tests/images/dispose_prev_first_frame_seeked.gif"
349+
)
350+
351+
344352
def test_previous_frame_loaded():
345353
with Image.open("Tests/images/dispose_none.gif") as img:
346354
img.load()

src/PIL/GifImagePlugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ def _seek(self, frame):
277277
if self.im:
278278
# only dispose the extent in this frame
279279
self.dispose = self._crop(self.im, self.dispose_extent)
280+
elif frame_transparency is not None:
281+
x0, y0, x1, y1 = self.dispose_extent
282+
dispose_size = (x1 - x0, y1 - y0)
283+
284+
Image._decompression_bomb_check(dispose_size)
285+
self.dispose = Image.core.fill(
286+
"P", dispose_size, frame_transparency
287+
)
280288
except AttributeError:
281289
pass
282290

0 commit comments

Comments
 (0)