- pngquant:
下載地址:https://pngquant.org/
pngquant 是一個(gè)批次轉(zhuǎn)換數(shù)值化和高頻振動(dòng)真彩PNG圖像的實(shí)用程序,特別是那些有一個(gè)完整的alpha通道,歸結(jié)為“rgba調(diào)色板”。這些圖像通常是兩到四次小于整個(gè)32位版本,和局部透明度是很好地保存下來。這使得pngquant特別是有用的對(duì)網(wǎng)站和PlayStation 2發(fā)展,其中一個(gè)紋理格式是基于rgba調(diào)色板(盡管不是png壓縮)。
終端輸入 pngquant -h 參數(shù)如下:
usage: pngquant [options] [ncolors] [pngfile [pngfile ...]]
options:
--force overwrite existing output files (synonym: -f)
--nofs disable Floyd-Steinberg dithering
--ext new.png set custom suffix/extension for output filename
--speed N speed/quality trade-off. 1=slow, 3=default, 10=fast & rough
--quality min-max don't save below min, use less colors below max (0-100)
--verbose print status messages (synonym: -v)
--iebug increase opacity to work around Internet Explorer 6 bug
--transbug transparent color will be placed at the end of the palette
Quantizes one or more 32-bit RGBA PNGs to 8-bit (or smaller) RGBA-palette
PNGs using Floyd-Steinberg diffusion dithering (unless disabled).
The output filename is the same as the input name except that
it ends in "-fs8.png", "-or8.png" or your custom extension (unless the
input is stdin, in which case the quantized image will go to stdout).
The default behavior if the output file exists is to skip the conversion;
use --force to overwrite.
其中-f參數(shù)已經(jīng)驗(yàn)證無效,參數(shù)說明可以參照官網(wǎng)里面。
開發(fā)中壓圖用默認(rèn)設(shè)置基本上可以了。
壓縮目錄下所有png圖片實(shí)例:
import os
# 獲取指定路徑下所有指定后綴的文件
# dir 指定路徑
# ext 指定后綴,鏈表&不需要帶點(diǎn) 或者不指定。例子:['xml', 'java']
def GetFileFromThisRootDir(dir, ext = None):
allfiles = []
needExtFilter = (ext != None)
for root,dirs,files in os.walk(dir):
for filespath in files:
filepath = os.path.join(root, filespath)
extension = os.path.splitext(filepath)[1][1:]
if needExtFilter and extension == ext in ext:
allfiles.append(filepath)
return allfiles
if __name__ == '__main__':
PngquantExe="/Users/*/PycharmProjects/QTPY/pngquant"
srcDir="/Users/*/Desktop/cutimg"
imgFiles=GetFileFromThisRootDir(srcDir, 'png')
suffix="_temp.png"
for f in imgFiles:
cmd = "\"" + PngquantExe + "\"" + " --ext " + suffix + " --force --speed=3 "+ f
os.system(cmd)
os.remove(f)
newfile=f.replace(".png", suffix)
os.rename(newfile, f)
ps:遙想當(dāng)初用PhotoShop壓圖真是慘不忍睹。