我对
python非常新鲜,试图用它将GIF的框架分割成PNG图像.
# Using this GIF: http://www.videogamesprites.net/FinalFantasy1/Party/Before/Fighter-Front.gif from PIL import Image im = Image.open('Fighter-Front.gif') transparency = im.info['transparency'] im.save('test1.png',transparency=transparency) im.seek(im.tell()+1) transparency = im.info['transparency'] im.save('test2.png',transparency=transparency) # First frame comes out perfect,second frame (test2.png) comes out black,# but in the "right shape",i.e. # http://i.stack.imgur.com/5GvzC.png
这是与我正在合作的形象有关,还是我做错了?
谢谢!
解决方法
我不认为你做错了什么看到类似的问题在这里:
animated GIF problem.看起来好像调色板信息未被正确处理的后期帧.以下为我工作:
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)