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

时间:2023-03-08 21:56:06

一、介绍

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

二、使用方法

1.下载并安装Image Magick

2.将脚本里的目录名改成Image Magick安装目录

3.把脚本放到图片目录下运行(图片可在文件夹里)

如果有图片不需要处理的话可以加入到IgnoreFileDic中

三、代码

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")