-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix issues with GIF transparency #3434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
e44f567
35c6ebd
68b844d
df10a72
b5806c7
87e54b4
2dcf6ca
4ff4770
644e7c0
60c068f
f96b405
be24990
8bfd763
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,11 +141,10 @@ def _seek(self, frame): | |
| self.dispose_extent = [0, 0, 0, 0] # x0, y0, x1, y1 | ||
| self.__frame = -1 | ||
| self.__fp.seek(self.__rewind) | ||
| self._prev_im = None | ||
| self.disposal_method = 0 | ||
| else: | ||
| # ensure that the previous frame was loaded | ||
| if not self.im: | ||
| if self.tile: | ||
| self.load() | ||
|
|
||
| if frame != self.__frame + 1: | ||
|
|
@@ -247,7 +246,7 @@ def _seek(self, frame): | |
| self.tile = [("gif", | ||
| (x0, y0, x1, y1), | ||
| self.__offset, | ||
| (bits, interlace))] | ||
| (bits, interlace, info.get("transparency", -1)))] | ||
| break | ||
|
|
||
| else: | ||
|
|
@@ -259,9 +258,10 @@ def _seek(self, frame): | |
| # do not dispose or none specified | ||
| self.dispose = None | ||
| elif self.disposal_method == 2: | ||
| # replace with background colour | ||
| self.dispose = Image.core.fill("P", self.size, | ||
| self.info["background"]) | ||
| # replace with transparency if there is one, otherwise | ||
| # background colour | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why potentially use the transparency? I don't see this in the spec.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've found https://legacy.imagemagick.org/Usage/anim_basics/#dispose
|
||
| bg = info.get("transparency", self.info["background"]) | ||
| self.dispose = Image.core.fill("P", self.size, bg) | ||
| else: | ||
| # replace with previous contents | ||
| if self.im: | ||
|
|
@@ -287,23 +287,19 @@ def _seek(self, frame): | |
| if self.palette: | ||
| self.mode = "P" | ||
|
|
||
| def load_prepare(self): | ||
| super(GifImageFile, self).load_prepare() | ||
|
|
||
| if self.__frame == 0: | ||
| # On the first frame, clear the buffer. Use the transparency index | ||
| # if we have one, otherwise use the background index. | ||
| default_color = self.info.get("transparency", | ||
| self.info.get("background", 0)) | ||
| self.im.paste(default_color, (0,0, self.size[0], self.size[1])) | ||
|
|
||
| def tell(self): | ||
| return self.__frame | ||
|
|
||
| def load_end(self): | ||
| ImageFile.ImageFile.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: | ||
| # 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() | ||
|
|
||
| def _close__fp(self): | ||
| try: | ||
| if self.__fp != self.fp: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.