我目前有一組plist文件。裏面是PNG圖像,一些文件有很多圖像。我正在使用win64 vista。如何從plist文件中提取png圖像?
我已經找過專門用於此目的的東西,比如FileJuicer,但那隻適用於mac用戶。
我目前有一組plist文件。裏面是PNG圖像,一些文件有很多圖像。我正在使用win64 vista。如何從plist文件中提取png圖像?
我已經找過專門用於此目的的東西,比如FileJuicer,但那隻適用於mac用戶。
哈哈,這是史蒂夫喬布斯所做的一切。你可以使用ChadBurggraf的庫https://github.com/ChadBurggraf/plists-cs來解析C#中的plist。但正如評論中所討論的那樣,你想要的文件可能不在plist文件中。
我寫了這個劇本解壓png
文件在plist
文件由TexturePacker
第一打包,請確保您有兩個在同一個目錄下的PNG和的plist文件,在我的情況:freeGifts.plist和freeGifts png格式
其次,下同腳本unpack_plist.py
然後,蟒蛇unpack_plist.py freeGifts,它會產生大量的PNG文件到一個名爲freeGifts
要求:python,PIL
#! /usr/lical/bin/python
import os,Image,sys
from xml.etree import ElementTree
def 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 d
def 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"
感謝Sean.Z.
爲unpack_plist.py,你需要:
1:PIL已經安裝在你的電腦上。
2:使用python 2.5
python2.5 unpack_plist.py birdfly
否則您將失敗。
----- 2013-07-25--
對於一些旋轉的plist,上面的腳本可能有一些bug。我修改它如下:
#python2.5 unpack_plist.py birdfly
#! /usr/lical/bin/python
import os,Image,sys
from xml.etree import ElementTree
def 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 d
def 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():
print "-----start\n----------"
rectlist = to_list(v['frame'])
print rectlist, "--------rectlist"
width = int(rectlist[3] if v['rotated'] else rectlist[2])
height = int(rectlist[2] if v['rotated'] else rectlist[3])
print width,height,"----width,height"
box=(
int(rectlist[0]),
int(rectlist[1]),
int(rectlist[0]) + width,
int(rectlist[1]) + height,
)
# bos is start & end point
print box,"-----_box-"
print v['rotated'], "---rotated"
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 result_box,"-----result_box-"
print outfile, "generated"
# result_image.save(outfile)
'''
if v['rotated']:
rect_on_big = rect_on_big.rotate(90)
if not os.path.isdir(file_path):
os.mkdir(file_path)
outfile = (file_path+'/' + k).replace('gift_', '')
rect_on_big.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"
感謝Sean.Z.第一。
但我發現旋轉不好,並且ygweric的補丁不夠好。
,因爲當png包含jpg文件(模式P)時它會失敗。有時透明將成爲黑色背景。
我試圖解決這個問題,我的代碼如下:
#! /usr/lical/bin/python import os,Image,sys from xml.etree import ElementTree def 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 d def 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) if v['rotated']: rect_on_big = rect_on_big.rotate(90) result_image = Image.new('RGBA', sizelist, (0,0,0,0)) if v['rotated']: result_box=( (sizelist[0] - height)/2, (sizelist[1] - width)/2, (sizelist[0] + height)/2, (sizelist[1] + width)/2 ) else: 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 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"
如果您有JRE在你的電腦,或者您也可以安裝,然後你可以使用我創建解壓的.plist文件的工具。它還支持在LibGdx項目中使用的.pack文件以及用於像unity這樣的許多引擎中的.xml文件來打包紋理。
我認爲plist文件是屬性列表文件。它們只包含圖像文件名,還是包含實際的圖像數據?如果是後者,它們是如何編碼的,或者什麼程序產生了它們? – 2011-05-22 07:25:21
http://www1.picturepush.com/photo/a/5700734/img/5700734.png 這個圖像是我認爲是代碼視圖中的一個樣子嗎? – CAN 2011-05-22 07:38:20
不包含任何像素數據。實際的png文件必須在別的地方。 BTW plist文件可以採用XML格式,因此可以是您發佈的plist文件原始內容的屏幕截圖。 – 2011-05-22 07:43:23