Merge pull request #5326 from radarhere/gif_disposal

Improved efficiency when creating GIF disposal images
This commit is contained in:
Hugo van Kemenade 2021-03-20 12:45:34 +02:00 committed by GitHub
commit 82b2f4aa36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -265,16 +265,20 @@ class GifImageFile(ImageFile.ImageFile):
self.dispose = None self.dispose = None
elif self.disposal_method == 2: elif self.disposal_method == 2:
# replace with background colour # replace with background colour
Image._decompression_bomb_check(self.size)
self.dispose = Image.core.fill("P", self.size, self.info["background"]) # only dispose the extent in this frame
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, self.info["background"]
)
else: else:
# replace with previous contents # replace with previous contents
if self.im: if self.im:
self.dispose = self.im.copy()
# only dispose the extent in this frame # only dispose the extent in this frame
if self.dispose: self.dispose = self._crop(self.im, self.dispose_extent)
self.dispose = self._crop(self.dispose, self.dispose_extent)
except (AttributeError, KeyError): except (AttributeError, KeyError):
pass pass