安装:
1 | yum install libpng libpng-devel && cd / && git clone --recursive https://github.com/kornelski/pngquant.git && cd /pngquant && ./configure && make && make install && pngquant -v && pip install pngquant |
使用:
1 2 3 4 5 6 7 8 9 10 11 12 13 | import pngquant #pngquant所在路径 pngquant.config('/usr/local/bin/pngquant') #需要压缩的文件 pngquant.quant_image('~/demo.png') #其它相关的api:quant_file程序文件,min_quality默认65,max_quality默认80,speed默认3,最高10(压缩率也相应少了10%) def config(self, quant_file=None, min_quality=None, max_quality=None, ndeep=None, ndigits=None, tmp_file=None, speed=None): #压缩image对象 def quant_data(self, data=None, dst=None, ndeep=None, ndigits=None, delete=True): #压缩image文件 def quant_image(self, image=None, dst=None, ndeep=None, ndigits=None, override=True, delete=True): #压缩某个目录下的png def quant_dir(self, dir=None, dst=None, ndeep=None, ndigits=None, override=True, delete=True, topdown=True): |