Python: Converting GIF frames to PNG

前端 未结 2 1510
灰色年华
灰色年华 2020-12-01 11:35

I\'m very new to python, trying to use it to split the frames of a GIF into PNG images.

# Using this GIF: http://www.videogamesprites.net/FinalFantasy1/Part         


        
相关标签:
2条回答
  • 2020-12-01 11:40

    I've fixed this bug here https://code.launchpad.net/~asdfghjkl-deactivatedaccount1/python-imaging/gif-fix.

    DSM's answer won't work if the GIF uses local color tables.

    0 讨论(0)
  • 2020-12-01 12:04

    I don't think you're doing anything wrong. See a similar issue here: animated GIF problem. It appears as if the palette information isn't correctly treated for later frames. The following works for me:

    def iter_frames(im):
        try:
            i= 0
            while 1:
                im.seek(i)
                imframe = im.copy()
                if i == 0: 
                    palette = imframe.getpalette()
                else:
                    imframe.putpalette(palette)
                yield imframe
                i += 1
        except EOFError:
            pass
    
    for i, frame in enumerate(iter_frames(im)):
        frame.save('test%d.png' % i,**frame.info)
    
    0 讨论(0)
提交回复
热议问题