資源簡介
自動分解多圖片的atlas文件,支持同一atlas下多圖片,支持atlas圖集,json圖集,支持拆分到子目錄。
代碼片段和文件信息
#encoding:utf-8
import?os
import?os.path
import?sys
import?glob??
import?platform
import?json
from?PIL?import?Image
currDir?=?os.path.dirname(os.path.realpath(sys.argv[0]))
print(“Curr?Dir:“+currDir)
#讀取Json
def?loadJson(filePath):
????if?os.path.exists(filePath)?:
????????json_file?=?open(filePath?mode=‘r‘?encoding=‘gbk‘)
????????data?=?json.load(json_file)
????????json_file.close()
????????return?data
????else:
????????return?False
?
def?split_png(pngPathfileJson):
????pnglist?=?fileJson[“frames“]
????meta?=?fileJson[“meta“]
????prefix?=?meta[“prefix“].split(“/“)[0]
????img?=?Image.open(pngPath)
????#?pathTar?=?os.path.join(currDir?prefix)
????#?if?not?os.path.exists(pathTar):
????#?????os.makedirs(pathTar)
????id?=?os.path.basename(pngPath).split(“.“)[0].replace(prefix““)
????if?id?==?““:
????????id?=?“0“
????for?key?in?pnglist:
????????each???=?pnglist[key]
????????#?print(each)
????????idx??=?each[“frame“][‘idx‘]
????????org_x??=?each[“frame“][‘x‘]
????????org_y??=?each[“frame“][‘y‘]
????????wid????=?each[“frame“][‘w‘]
????????height?=?each[“frame“][‘h‘]
????????if?hasattr(each?‘rotated‘)?==?True?and?each[‘rotated‘]?==True:
????????????region?=?(org_xorg_yorg_x+heightorg_y+wid)
????????elif?hasattr(each?‘rotated‘)?==False:
????????????region?=?(org_xorg_yorg_x+widorg_y+height)
????????#?print(‘============?%d?%d?%d?%d‘?%(org_xorg_ywidheight))
????????if?id?==?str(idx):
????????????checkDirTar(prefix?id)
????????????#裁切圖片
????????????cropIm
- 上一篇:《Python程序設計》題庫
- 下一篇:磁力搜索完善源碼
評論
共有 條評論