Python:将GIF框架转换为PNG
发布时间:2020-05-23 10:03:10 所属栏目:Python 来源:互联网
导读:我对 python非常新鲜,试图用它将GIF的框架分割成PNG图像. # Using this GIF: http://www.videogamesprites.net/FinalFantasy1/Party/Before/Fighter-Front.giffrom PIL import Imageim = Image.open(Fighter-Front.gif)transpare
|
我对 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) (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
