Skip to content

Commit

Permalink
Merge pull request #5125 from radarhere/disposal_method
Browse files Browse the repository at this point in the history
Use previous disposal method in GIF load_end
  • Loading branch information
hugovk committed Dec 29, 2020
2 parents 1892b23 + 9940c84 commit cd446e6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
Binary file added Tests/images/dispose_none_load_end.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/dispose_none_load_end_second.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions Tests/test_file_gif.py
Expand Up @@ -307,6 +307,20 @@ def test_dispose_none():
pass


def test_dispose_none_load_end():
# Test image created with:
#
# im = Image.open("transparent.gif")
# im_rotated = im.rotate(180)
# im.save("dispose_none_load_end.gif",
# save_all=True, append_images=[im_rotated], disposal=[1,2])
with Image.open("Tests/images/dispose_none_load_end.gif") as img:
img.seek(1)

with Image.open("Tests/images/dispose_none_load_end_second.gif") as expected:
assert_image_equal(img, expected)


def test_dispose_background():
with Image.open("Tests/images/dispose_bgnd.gif") as img:
try:
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/GifImagePlugin.py
Expand Up @@ -301,13 +301,14 @@ def load_end(self):

# if the disposal method is 'do not dispose', transparent
# pixels should show the content of the previous frame
if self._prev_im and self.disposal_method == 1:
if self._prev_im and self._prev_disposal_method == 1:
# we do this by pasting the updated area onto the previous
# frame which we then use as the current image content
updated = self._crop(self.im, self.dispose_extent)
self._prev_im.paste(updated, self.dispose_extent, updated.convert("RGBA"))
self.im = self._prev_im
self._prev_im = self.im.copy()
self._prev_disposal_method = self.disposal_method

def _close__fp(self):
try:
Expand Down

0 comments on commit cd446e6

Please sign in to comment.