Skip to content
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

Only crop GIF frames when saving with disposal method 2 if transparency is present #8748

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

radarhere
Copy link
Member

Resolves #8746

When GIF frames are saved, Pillow crops out parts of frames i order to save space.

In #5557, I found https://legacy.imagemagick.org/Usage/anim_basics/#dispose. In the 'Dispose Background' section (a.k.a. disposal method 2), it states that

As you can see as each overlaid frame is disposed of, that frames area is cleared to transparency, before the next image is overlaid.
...
There is some thinking that rather than clearing the overlaid area to the transparent color, this disposal should clear it to the 'background' color meta-data setting stored in the GIF animation. In fact the old "Netscape" browser (version 2 and 3), did exactly that. But then it also failed to implement the 'Previous' dispose method correctly.
On the other hand the initial canvas should also be set from the formats 'background' color too, and that is also not done. However all modern web browsers clear just the area that was last overlaid to transparency, as such this is now accepted practice, and what IM now follows.

So there is apparently a convention to clear to transparency for disposal method 2, rather than the background colour as described by the specification. The new issue has found this to be a problem with our saved GIFs.

To fix this, when saving with disposal method 2, this PR will only crop if there is transparency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GIF encoder: black pixels incorrectly cropped when disposal=2
1 participant