-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimUn.py
More file actions
68 lines (57 loc) · 1.9 KB
/
Copy pathanimUn.py
File metadata and controls
68 lines (57 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!user/bin/env python
# -*- coding: utf-8 -*-
#分解 由cocosAnimation 打包成的大图
import sys
import os
import xml.etree.ElementTree as ET
from PIL import Image
__author__ = "qingsen"
def getImgsInfo(plistFile):
images = []
root = ET.fromstring(open(plistFile,'r').read())
frames = root[0][1]
for imageName in frames.findall("key"): #findall :当前标签 所有子key标签
name = imageName.text
pos = imageName.text.find("/")
if pos >= 0 :
name = imageName.text[pos+1:len(imageName.text)]
print name
d = {}
d["imageName"] = name
images.append(d)
print len(images)
i = 0
for info in frames.findall("dict"):
images[i]["width"] = int(info[1].text)
images[i]["height"] = int(info[3].text)
images[i]["x"] = int(info[9].text)
images[i]["y"] = int(info[11].text)
i = i + 1
return images
def decompos(plistFile,pngFile):
bigImage = Image.open(pngFile)
images= getImgsInfo(plistFile)
fileName = plistFile.replace(".plist","")
for image in images:
box = (image["x"],image["y"],image["x"]+image["width"],image["y"]+image["height"])
childImg = bigImage.crop(box)
if not os.path.isdir(fileName):
os.mkdir(fileName)
outfile = (fileName+'/' + image["imageName"])
print outfile
childImg.save(outfile)
def main():
# python decompos.py 文件名 (会在同级目录下生成同名的文件夹放分解后的小图)
args = sys.argv
if len(args) == 2:
filename = args[1]
plistFile = filename + '.plist'
pngFile = filename + '.png'
if (os.path.exists(plistFile) and os.path.exists(pngFile)):
decompos(plistFile,pngFile)
else:
print u"文件缺失"
else:
print u"输入要分解的文件名"
if __name__ == '__main__':
main()