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

Last frame of gif has second last frame merged to it #3153

Closed
s0hv opened this issue Jun 1, 2018 · 3 comments · Fixed by #5125
Closed

Last frame of gif has second last frame merged to it #3153

s0hv opened this issue Jun 1, 2018 · 3 comments · Fixed by #5125
Labels
Projects

Comments

@s0hv
Copy link

s0hv commented Jun 1, 2018

What did you do?

I iterated through gif frames and added copies of the frames converted to rgba to a list of the following 4 frame gif gif

This was the code I used and what produced the invalid result

frames = []
while True:
    frames.append(im.copy().convert('RGBA'))
    try:
        im.seek(im.tell() + 1)
    except EOFError:
        break

What did you expect to happen?

Expected that all the frames would look normal without them merging

What actually happened?

The last 2 images merged Invalid frame as in the following pic when the expected result would be Correct frame
The second last frame was kept normal but the last frame included the second last frame merged to it
I was able to get the desired result by using the following modification of my original loop

frames = []
while True:
    frames.append(im.copy().convert('RGBA'))
    try:
        im.seek(im.tell() + 1)
    except EOFError:
        frames[-1] = im.copy().convert('RGBA')
        break

What versions of Pillow and Python are you using?

Python 3.6.4
Pillow 5.1.0

@radarhere radarhere added the GIF label Jun 1, 2018
@radarhere
Copy link
Member

GIFs have a value called a 'disposal method'. For the last frame in this image, it is set to 'Do not dispose. The graphic is to be left in place.'

So from what I can see, Pillow is behaving correctly. Clearly standard image viewers have other ideas about what to do in this situation though, and I don't know what logic they are using.

@radarhere
Copy link
Member

This is resolved by #3434.

I'm also going to move discussion of #3665 (comment) here, which looks like the same problem, and is also solved by #3434.

import requests
from PIL import Image
response = requests.get('https://66.media.tumblr.com/tumblr_lzkp40b0Sl1qhwcy0.gif')
im = Image.open(BytesIO(response.content))
im.save('1.png', 'PNG')
im.seek(1)
im.load()
im.save('2.png', 'PNG')

The 2.png has second frame pasted onto first.
Expected result is second frame pasted into background (transparent).

@radarhere
Copy link
Member

I've created PR #5125 to resolve this.

Pillow automation moved this from In progress to Closed Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Pillow
  
Closed
Development

Successfully merging a pull request may close this issue.

2 participants