图片压缩工具imageoptim在git的集成

过程是看看有没有装这个软件,如果没有装就先下载再装上,然后开始进行检索所有的图片,然后把图片传入这个软件,打开进行压缩

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
#coding:utf-8
import sys,os,time,shutil
import urllib
import urllib2
import zipfile
import tarfile
def un_tar(file_name):
tar = tarfile.open(file_name)
names = tar.getnames()
if os.path.isdir(file_name + "_files"):
pass
else:
os.mkdir(file_name + "_files")
#因为解压后是很多文件,预先建立同名目录
for name in names:
tar.extract(name, file_name + "_files/")
tar.close()
if os.path.exists('/Applications/ImageOptim.app') == False:
print '下载'
un_tar('ImageOptim.tar')
shutil.copytree('ImageOptim.tar_files/ImageOptim.app','/Applications/ImageOptim.app')
text = os.popen('find . -name *.png').read()
images = text.split('n')
imagepaths = ''
for x in xrange(1,200):
image = images[x]
if chr(32) in image:
print '该文件不可用,请去除文件名字的空格' + image
continue
imagepaths = imagepaths + ' ' + image
os.system('open -a ImageOptim ' + imagepaths)