【图片处理】cocos2dx png图片压缩处理

1、介绍

美术用photoshop出图有时候会包含一些无用的信息,这时候image magick能够把这些信息裁掉。python

2、使用方法

1.下载并安装Image Magick
2.将脚本里的目录名改为Image Magick安装目录
3.把脚本放到图片目录下运行(图片可在文件夹里)
若是有图片不须要处理的话能够加入到IgnoreFileDic中app

3、代码

import os
import sys

#usage: run this script in image folder

#image magick convert file path
CMD = r'C:\\Program Files\\ImageMagick-6.9.0-Q16\\convert.exe'

#filename contains in dic will be ignored 
IgnoreFileDic = {"test.png" : True}

def getFile(path):
    fileArr = [];
    for root, dirs, files in os.walk(path):
        for fileStr in files:   
            name = fileStr.lower();
            if name.find('.png') != -1:
                if not IgnoreFileDic.has_key(name):    
                    filePath = os.path.join(root, fileStr)
                    fileArr.append(filePath)
    return fileArr

def doStrip(fileArr):
    totalNum = len(fileArr)
    for i in range(0, len(fileArr)):
        filePath = fileArr[i]
        print '\rStrip Progress: %d/%d' % (i+1,totalNum),
        os.system('"{0}" {1} -strip {1}'.format(CMD, filePath, filePath));

if __name__ == '__main__': 
    sourcePath = sys.path[0]
    print("Image Path:%s" % sourcePath)
    fileArr = getFile(sourcePath)
    print("Image strip start!--->>>")
    doStrip(fileArr)
    print("\n--->>>Image strip finish")
相关文章
相关标签/搜索