Use previous disposal method in load_end

This commit is contained in:
Andrew Murray 2020-12-23 13:22:53 +11:00
parent ce3d80e713
commit 9940c84b08
4 changed files with 16 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -307,6 +307,20 @@ def test_dispose_none():
pass 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(): def test_dispose_background():
with Image.open("Tests/images/dispose_bgnd.gif") as img: with Image.open("Tests/images/dispose_bgnd.gif") as img:
try: try:

View File

@ -301,13 +301,14 @@ class GifImageFile(ImageFile.ImageFile):
# if the disposal method is 'do not dispose', transparent # if the disposal method is 'do not dispose', transparent
# pixels should show the content of the previous frame # 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 # we do this by pasting the updated area onto the previous
# frame which we then use as the current image content # frame which we then use as the current image content
updated = self._crop(self.im, self.dispose_extent) updated = self._crop(self.im, self.dispose_extent)
self._prev_im.paste(updated, self.dispose_extent, updated.convert("RGBA")) self._prev_im.paste(updated, self.dispose_extent, updated.convert("RGBA"))
self.im = self._prev_im self.im = self._prev_im
self._prev_im = self.im.copy() self._prev_im = self.im.copy()
self._prev_disposal_method = self.disposal_method
def _close__fp(self): def _close__fp(self):
try: try: