diff --git a/Tests/images/dispose_prev_first_frame.gif b/Tests/images/dispose_prev_first_frame.gif new file mode 100644 index 000000000..4c19dd1ed Binary files /dev/null and b/Tests/images/dispose_prev_first_frame.gif differ diff --git a/Tests/images/dispose_prev_first_frame_seeked.gif b/Tests/images/dispose_prev_first_frame_seeked.gif new file mode 100644 index 000000000..bc3eb1393 Binary files /dev/null and b/Tests/images/dispose_prev_first_frame_seeked.gif differ diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 6d92bde76..df029dceb 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -341,6 +341,14 @@ def test_dispose_previous(): pass +def test_dispose_previous_first_frame(): + with Image.open("Tests/images/dispose_prev_first_frame.gif") as im: + im.seek(1) + assert_image_equal_tofile( + im, "Tests/images/dispose_prev_first_frame_seeked.gif" + ) + + def test_previous_frame_loaded(): with Image.open("Tests/images/dispose_none.gif") as img: img.load() diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index 3c4cb6187..5c93de2c9 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -277,6 +277,14 @@ class GifImageFile(ImageFile.ImageFile): if self.im: # only dispose the extent in this frame self.dispose = self._crop(self.im, self.dispose_extent) + elif frame_transparency is not None: + x0, y0, x1, y1 = self.dispose_extent + dispose_size = (x1 - x0, y1 - y0) + + Image._decompression_bomb_check(dispose_size) + self.dispose = Image.core.fill( + "P", dispose_size, frame_transparency + ) except AttributeError: pass