我对
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)
原文地址:https://www.jb51.cc/python/186700.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。