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

Animated GIFs aren't correct after first frame and lost transparency #1976

Closed
docapotamus opened this issue Jun 21, 2016 · 7 comments
Closed
Labels
Bug Any unexpected behavior, until confirmed feature. GIF Palette
Projects

Comments

@docapotamus
Copy link

docapotamus commented Jun 21, 2016

What did you do?

I open an animated GIF and immediately save it back out to another file.

What did you expect to happen?

The image to be the same as it was when it was uploaded.

What actually happened?

The transparency is gone on the first frame and all subsequent frames have a black background.

What versions of Pillow and Python are you using?

3.2.0

Please include code that reproduces the issue and whenever possible, an image that demonstrates the issue. The best reproductions are self-contained scripts with minimal dependencies.

banana
output

from PIL import Image                                                           
img = Image.open('banana.gif')
img.save('output.gif', format='GIF', save_all=True)

I am aware there are a lot of issues related to animated GIFs but I am struggling to get a coherent understanding of the issue.

I have other GIFs which act differently and just distort all subsequent frames.
otter
output

I am happy to provide any more information if needed. I'm willing to fix this myself if needs be. I just don't know enough about Pillow's internals or where to even start with an issue like this.

I forgot to add there is an error appearing which says a colour can't be found for transparent. I will post the actual error later when I am at my computer.

Thanks in advance.

@radarhere
Copy link
Member

I feel like looking at #1525 would be a good starting point.

@wiredfool
Copy link
Member

Also suspect that this is appropriate: #1987 (comment)

@wiredfool wiredfool added GIF Bug Any unexpected behavior, until confirmed feature. Palette and removed GIF labels Jun 30, 2016
@docapotamus
Copy link
Author

Thanks for the links. I did try a few of these with no success. I opened this mainly because it was incredibly hard to round up all the information on GIF issues.

Unfortunately this was blocking a feature request for us so we have had to use a different package. I wish I had the time to look into and try fix this myself.

@radarhere radarhere changed the title Animated GIFs aren't correct after first frame and lost transparent Animated GIFs aren't correct after first frame and lost transparency Dec 22, 2018
@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to Icebox in Pillow May 11, 2019
@xjcl
Copy link

xjcl commented Jan 14, 2020

I documented a workaround for this on StackOverflow: https://stackoverflow.com/a/59729588/2111778 :-)

I hope this gets fixed soon as this is really just a case of also copying the transparency value to the images in append_images.

@radarhere
Copy link
Member

Since #5125, I find that using disposal 2 creates a working image.

from PIL import Image                                                           
img = Image.open('banana.gif')
img.save('output.gif', format='GIF', save_all=True, disposal=2)

Testing, I find that #2103 fixed the otter problem.

Pillow automation moved this from Icebox to Closed Mar 17, 2021
@xjcl
Copy link

xjcl commented Mar 23, 2021

So if I understand correctly, using disposal=2 was broken (as documented in my StackOverflow answer) and got fixed in #5125? Sadly I haven't kept the input files so I can't help verify this :/

In which versions of pillow would this be fixed?

@radarhere
Copy link
Member

There are multiple Pillow issues regarding GIF, some fixed, some not. So without talking about a specific image, it's hard to have a discussion.

For some reason if I try and go back to Pillow 3.2 - Pillow 4.0, I get ValueError: unrecognized raw mode, which clearly wasn't a problem in this issue, so I don't know why that is.

After that, #2902 added the disposal option when saving. Without that, each new frame of the banana GIF just stacks on top of the others.

#3708 fixed an issue with disposal method 2, where the last frame of the output banana GIF was cropped wrongly.

#5125 was released as part of Pillow 8.1.0. This fixed a problem if the disposal method was not the same throughout a GIF. Before that, the last frame of the output banana GIF wrongly included a copy of the second last frame.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature. GIF Palette
Projects
Pillow
  
Closed
Development

No branches or pull requests

4 participants