Unpack Png Files From The Plist File
来源:互联网 发布:xampp配置mysql端口 编辑:程序博客网 时间:2024/06/07 05:47
first, make sure you have both the png and plist files in the same directory, in my case: freeGifts.plist and freeGifts.png
second, save the following script as unpack_plist.py
then, python unpack_plist.py freeGifts, it will generate lots of png files to a directory named freeGifts
requirement: python, PIL
#! /usr/lical/bin/pythonimport os,Image,sysfrom xml.etree import ElementTreedef tree_to_dict(tree): d = {} for index, item in enumerate(tree): if item.tag == 'key': if tree[index+1].tag == 'string': d[item.text] = tree[index + 1].text elif tree[index + 1].tag == 'true': d[item.text] = True elif tree[index + 1].tag == 'false': d[item.text] = False elif tree[index+1].tag == 'dict': d[item.text] = tree_to_dict(tree[index+1]) return ddef gen_png_from_plist(plist_filename, png_filename): file_path = plist_filename.replace('.plist', '') big_image = Image.open(png_filename) root = ElementTree.fromstring(open(plist_filename, 'r').read()) plist_dict = tree_to_dict(root[0]) to_list = lambda x: x.replace('{','').replace('}','').split(',') for k,v in plist_dict['frames'].items(): rectlist = to_list(v['frame']) width = int( rectlist[3] if v['rotated'] else rectlist[2] ) height = int( rectlist[2] if v['rotated'] else rectlist[3] ) box=( int(rectlist[0]), int(rectlist[1]), int(rectlist[0]) + width, int(rectlist[1]) + height, ) sizelist = [ int(x) for x in to_list(v['sourceSize'])] rect_on_big = big_image.crop(box) result_image = Image.new('RGBA', sizelist, (0,0,0,0)) result_box=( ( sizelist[0] - width )/2, ( sizelist[1] - height )/2, ( sizelist[0] + width )/2, ( sizelist[1] + height )/2 ) result_image.paste(rect_on_big, result_box, mask=0) if v['rotated']: result_image = result_image.rotate(90) if not os.path.isdir(file_path): os.mkdir(file_path) outfile = (file_path+'/' + k).replace('gift_', '') print outfile, "generated" result_image.save(outfile)if __name__ == '__main__': filename = sys.argv[1] plist_filename = filename + '.plist' png_filename = filename + '.png' if (os.path.exists(plist_filename) and os.path.exists(png_filename)): gen_png_from_plist( plist_filename, png_filename ) else: print "make sure you have boith plist and png files in the same directory"
原文:http://stackoverflow.com/questions/6086615/how-can-i-extract-png-images-from-plist-files
0 0
- Unpack Png Files From The Plist File
- Loading data from .plist files
- could not read data from '/Users/xxxx/xxxx/Info.plist': The file “Info.plist” couldn’t be opened
- could not read data from 'Configurat'/Info.plist': The file “plist” couldn’t be opened because there
- could not read data from '/Users/xxxx/xxxx/Info.plist': The file “Info.plist” couldn’t be opened
- could not read data from '/Users/xxxx/xxxx/Info.plist': The file “Info.plist” couldn’t be opened
- Create PVR texture from png file
- Get data from file(xxx.png) failed!
- Get data from file(xxx.png) failed!
- Copying files from ASM to file system
- could not read data from '/Users/iamme/Documents/XCode/myapp/myapp/myapp-Info.plist': The file “myap
- windows batch file : backup the SAM files
- Xcode missing file or .png is missing from working copy
- Cocos2d: Get data from file(image.png) failed!
- How to export files from rpm file on ubuntu system
- --allow-file-access-from-files 命令的使用
- AjaxJquery 加载不了本地文件--allow-file-access-from-files
- how to generate pb file from ckpt files?
- 递进--求两个数的公约数
- 地柜函数实现二进制数
- 第11周 项目二 (1) 求两个数最大公约数
- 第十二周 项目二 (1)求多组数的最大公约数
- XHR2:让使用纯JS实现上传进度条变成了可能
- Unpack Png Files From The Plist File
- android-实时监听网络变化的工具类
- 时间设置对话框 DatePickerDialog的使用
- 在升级最新discuzX3.1-X3.2之后验证码不显示解决方法
- sql基本语句
- [manacher] hdu 3294 Girls' research
- sqlmap源码阅读笔记---LOGGER
- Android 实现界面之间的转跳
- 第12周项目3-用递归方法求解(1)