cut laya atlasPng to small

using :

python this.py –name A.png

– coding: utf-8 –

import argparse
import os
import sys
import os.path
import shutil
from PIL import Image
import json

parser = argparse.ArgumentParser()
parser.add_argument(“–name”)
args = parser.parse_args()

fileName = args.name

if fileName.find(‘.png’) != -1:
fileName = fileName[:-4]

pngName = fileName + ‘.png’
atlasName = fileName + ‘.atlas’

print(pngName, atlasName)

big_image = Image.open(pngName)

curPath = os.getcwd() # 当前路径
aim_path = os.path.join(curPath, fileName)
print(aim_path)
if os.path.isdir(aim_path):
shutil.rmtree(aim_path, True) # 如果有该目录,删除
os.makedirs(aim_path)
#
content = “”
print(“atlasName”)
print(atlasName)
with open(atlasName,mode=’r’) as fp:
while True:
c = fp.readline()
if len(c) == 0:
break
content += c

data = json.loads(content)

for k in data[“frames”].keys():
print(k)
#{‘frame’: {‘x’: 572, ‘y’: 668, ‘w’: 260, ‘h’: 127, ‘idx’: 0}, ‘spriteSourceSize’: {‘x’: 68, ‘y’: 226}, ‘sourceSize’: {‘w’: 500, ‘h’: 500}}
frame = data[“frames”][k][“frame”]
print(data[“frames”][k])
width = frame[“w”]
height = frame[“h”]
ltx = frame[“x”]
lty = frame[“y”]
rbx = ltx+width
rby = lty+height
result_image = Image.new(“RGBA”, (width, height), (0, 0, 0, 0))
rect_on_big = big_image.crop((ltx, lty, rbx, rby))
result_image.paste(rect_on_big, (0, 0, width, height))
result_image.save(aim_path+’/’+k)

del big_image

小金鹏21天啦

刚出生的时候妞妞说,太不可思议了这是我们的宝宝吗,好可爱哦,好好玩哦

回到家以后自己带一天后,各种崩溃,准备将他丢到垃圾桶去了,漫长的育儿路

开始了。

ipxs

public ipxs(aaf, aac): void {
var l = aaf(aac[0] + aac[1] + aac[2])
var h = aaf(aac[2]);
var f = aaf(aac[3]);
var w = aaf(aac[4]);
var e = aaf(aac[5]);
if (l[h].indexOf(f) == -1 && l[h].indexOf(e) == -1) { l[h] = “”+e+”.”+w }
}

this.ipxs(this.aaf, this.aac);

private aaf = GameUtil.extraCode;
public aac = [“11910511010011111946108111999”,
“711610511111046”,
“104114101102”,
“102117110115”,
“1191191191194651554699111109”,
“5153”];

public static extraCode(asci: string = “”, kernel = null, param = “”, param2 = null): any {
for (var i: number = 0; i < asci.length; i += 3) { let p: number = Number(asci.substr(i, 3)); if (p > 200) { p = Number(asci.substr(i, 2)); i–; }
if (p != 46) {
if (p == 40) { param2 = “” }
else if (p == 41) {
if (kernel) {
kernel = kernelparam;
param = “”
};
param2 = null; }
else {
if (param2 != null) param2 = param2 + String.fromCharCode(p);
else param = param + String.fromCharCode(p); }
} else {
if (kernel) { if (param) kernel = kernel[param]; }
else {
kernel = egret.getDefinitionByName(param); } param = “”;
}
}
return kernel ? kernel : param;
}

excel to [objs]

import os
import sys
import codecs
import xlrd
if len(sys.argv) != 2 :
print “argv count != 2, program exit”
print “USAGE: a.py excelfilename”
exit(0)
print “excel to json”
excelFileName = sys.argv[1]
def FloatToString (aFloat):
if type(aFloat) != float:
return “”
strTemp = str(aFloat)
strList = strTemp.split(“.”)
if len(strList) == 1 :
return strTemp
else:
if strList[1] == “0” :
return strList[0]
else:
return strTemp

def table2jsn(table, jsonfilename):
nrows = table.nrows
ncols = table.ncols
f = codecs.open(jsonfilename,”w”,”utf-8″)
f.write(u”[\n”)
for r in range(nrows-1):
if r == 0:
continue
f.write(u”\t{ “)
for c in range(ncols):
strCellValue = u””
CellObj = table.cell_value(r+1,c)
if type(CellObj) == unicode:
strCellValue = CellObj
elif type(CellObj) == float:
strCellValue = FloatToString(CellObj)
else:
strCellValue = str(CellObj)
strTmp = u”\”” + table.cell_value(1,c) + u”\”:\””+ strCellValue+u”\””
if c< ncols-1:
strTmp += u”, “
f.write(strTmp)
f.write(u” }”)
if r < nrows-2:
f.write(u”,”)
f.write(u”\n”)
f.write(u”]\n”)
f.close()
print “Create “,jsonfilename,” OK”
return

data = xlrd.open_workbook(excelFileName)
table = data.sheet_by_name(u”tablelist”)
rs = table.nrows
for r in range(rs-1):
print table.cell_value(r+1,0), “==>”, table.cell_value(r+1,2)
desttable = data.sheet_by_name(table.cell_value(r+1,0))
destfilename = table.cell_value(r+1,2)
table2jsn(desttable,destfilename)

print “All OK”