import tinify
import os
g_pro_root_path = ""
g_res_root_path = ""
tinify.key = " " #自己的key
def listFile(filePath):
print g_res_root_path
if os.path.isdir(filePath) :
for file in os.listdir(filePath):
if os.path.isdir(os.path.join(filePath, file)):
listFile(os.path.join(filePath, file))
else:
compressFile(os.path.join(filePath, file))
print "compress complete!!!"
def compressFile(fileName):
expandName = os.path.splitext(fileName)
if expandName[1] == ".png":
source = tinify.from_file(fileName)
source.to_file(fileName)
print os.path.split(fileName)[1] + " compress success~~"
if "__name == __main__":
g_pro_root_path = os.path.dirname(os.getcwd())
g_res_root_path = os.path.join(g_pro_root_path, "res/sd/images")
listFile(g_res_root_path)
网友评论