您的位置:首页 > 编程语言 > Python开发

texturepacker使用python调用命令行对批量图片进行打包

2017-11-03 18:53 1481 查看
我的python版本是2.7,texturepacker版本是3.2.1,使用的操作系统是windows7。如果是在MAC或者Linux下方法也是一样的。texturepacker支持mac系统,但不知道是否支持linux。

啥也不说了,直接上python的脚本。 
# -*- coding: cp936 -*-
import os,sys
imagedir = 'D:\\SVN\\前端\\公共\\武将图片\\hero1230'#图片所在文件夹
outplistdir = 'D:\\SVN\\前端\\公共\\武将图片\\AllHeroPlist'#打包后输出的文件夹
comend = 'texturepacker'#图片打包软件,这里要把这个软件加入到环境变量中,要不然就要写这个软件的完整路径
print "imagedir = %s \noutdir = "%imagedir,outplistdir
herolist = os.listdir(imagedir)
print "heave %d hero convert"%len(herolist)
for n in range(len(herolist)):
  herodirtmp = imagedir + os.sep + herolist

  herotmplist = os.listdir(herodirtmp)
  cmdtmp = comend
  print "hero %s heave image = %d"%(str(herolist
),len(herotmplist))
  allImage = ""
  for im in range(len(herotmplist)):
    allImage = allImage + " " + herodirtmp + os.sep + herotmplist[im]
  cmdtmp = cmdtmp + " " + allImage +\
           " --data " + outplistdir + os.sep + herolist
+ ".plist"\
           " --sheet " + outplistdir + os.sep + herolist
+ ".pvr.ccz"\
           " --opt RGBA4444 --dither-fs-alpha --content-protection \
19e5c826f732e5325e58d0c52488c7ac"
  os.system(cmdtmp)
我是把texturepacker所在位置加入到了环境变量中,如果你没有加你就要在运行命行的时候cd到这个目录,或者写上程序的全路径,要查看texturepacker的帮助,只要在命令提示行下输入texturepacker就可以看到了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: