• 大小: 3KB
    文件类型: .py
    金币: 1
    下载: 0 次
    发布日期: 2021-06-12
  • 语言: Python
  • 标签: python  

资源简介

自动分解多图片的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

评论

共有 条评论