More problems extracting frames from GIFs
Question: Following my previous question ([Gifs opened with python have broken
frames](http://stackoverflow.com/questions/21990868/gifs-opened-with-python-
have-broken-frames)) I now have code that works sometimes.

For example, this code

    
    
    from PIL import Image
    
    img = Image.open('pigs.gif')
    
    counter = 0
    collection = []
    current = img.convert('RGBA')
    while True:
        try:
            current.save('original%d.png' % counter, 'PNG')
            img.seek(img.tell()+1)
            current = Image.alpha_composite(current, img.convert('RGBA'))
            counter += 1
        except EOFError:
            break
    

…works on most GIFs perfectly, but on others it produces weird results. For
example, when applied to this 2-frame GIF:

![GIF](http://i.stack.imgur.com/svgPU.gif)

It produces these two frames:

![Frame 1](http://i.stack.imgur.com/tSRpH.png) ![Frame
2](http://i.stack.imgur.com/IKGlP.png)

The first one is ok, the second one not so much.

What now?


Answer: Sounds like you want to do this:

    
    
    while True:
        try:
            current.save('original%d.gif' % counter)
            img.seek(img.tell()+1)
            current = img.convert('RGBA')
            counter += 1
        except EOFError:
            break
    

