資源簡介
自動分解多圖片的atlas文件,支持同一atlas下多圖片,支持拆分到子目錄。
代碼片段和文件信息
#?-*-?coding:?utf-8?-*-
#?感謝mingyuan2575的單圖片代碼
“““
?作者:Lthcwsw
?功能:自動分解多圖片的atlas文件
?說明:
1、安裝Python?2.7.12,全裝,特別是要裝pip
2、安裝PIL。pip?install?pil?或者?pip?install?pillow
3、復制ff.py腳本進圖片目錄運行
“““
import?os
import?sys
import?os.path
import?shutil
from?PIL?import?Image
def?lineType(str):
if?len(str)?==?0:
return?1 #?文件結束
else:
str?=?str.replace(“\n“““)
str?=?str.replace(“?“““)
if?len(str)?==?0:
return?2 #?空行,另一個圖片文件
return?3
def?ReadPng():
global?atlas
line?=?atlas.readline()
line?=?line.replace(“\n“““)
pngName?=?line
if?not?os.path.isfile(pngName): #圖片文件不存在
print?(pngName?+?‘?file?is?not?exist‘)
return
else:
big_image?=?Image.open(pngName)
_line?=?atlas.readline(); #?size
_line?=?atlas.readline(); #?format
_line?=?atlas.readline(); #?filter
_line?=?atlas.readline(); #?repeat
while?True:
line1?=?atlas.readline()?#?name
if?lineType(line1)?==?1:
break
elif?lineType(line1)?==?2:
ReadPng()
else:
line2?=?atlas.readline()?#?rotate
line3?=?atlas.readline()?#?xy
line4?=?atlas.readline()?#?size
line5?=?atlas.readline()?#?orig
line6?=?atlas.readline()?#?offset
line7?=?atlas.readline()?#?index
name?=?line1.replace(“\n“““)?+?“.png“;
args?=?line4.split(“:“)[1].split(““);
width?=?int(args[0])
height=?int(args[1])
評論
共有 條評論