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

Use transparency behind first GIF frame and when disposing to background #5557

Merged
merged 4 commits into from Jun 27, 2021

Conversation

radarhere
Copy link
Member

Resolves #5548

The issue provides a single frame GIF with a dispose_extent of (0, 0, 27, 32) - which is not the full size of the image.

The spec states that

The Background Color is the color used for those pixels on the screen that are not covered by an image.

However, other software shows this area as transparent instead. This PR is where I give in to this apparently universal convention.

I created the test image here with Pillow.

Credit to df10a72 for the start of this code - although that commit falls back to the background color if there is no transparency. I don't find that behaviour from other software, so I've not included it here.

@radarhere
Copy link
Member Author

Using transparency behind the first frame is one remaining part of #3434. The other part is a change to dispose to transparency for disposal method 2, instead of to background color.

I've found https://legacy.imagemagick.org/Usage/anim_basics/#dispose. In the 'Dispose Background' section, 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 I'm going with that. I've now added the rest of #3434 to this issue.

@radarhere radarhere changed the title Draw first GIF frame on top of transparency Use transparency behind first GIF frame and when disposing to background Jun 25, 2021
@hugovk hugovk merged commit 00303a2 into python-pillow:master Jun 27, 2021
@radarhere radarhere deleted the gif_first_frame_transparency branch June 27, 2021 21:01
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.

AnimGIF not transparent
3 participants