zopflipng 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

zopflipng 命令安装:


-bash/zsh: zopflipng command not found

#Debian
apt-get install zopfli

#Ubuntu
apt-get install zopfli

#Arch Linux
pacman -S zopfli

#Kali Linux
apt-get install zopfli

#Fedora
dnf install zopfli

#OS X
brew install zopfli

#Raspbian
apt-get install zopfli

------------------
编译安装:
git clone https://github.com/google/zopfli.git

cd zopfli/
make ..

将编译后的文件,复制到 /bin 目录

zopflipng 命令补充说明:


Zopfli 是一个数据压缩算法,可以将数据压缩为 DEFLATE、gzip 或 zlib 格式。Zopfli 被认为是目前压缩率最高的 DEFLATE 压缩算法。2013 年 2 月,Google 将 Zopfli 算法的一个参考实现以 Apache 许可证 2.0 发布为自由软件程序库。名称 Zöpfli 是瑞士德语 Zopf(一种不加糖的花环面包)的指小形式。

PNG 格式在图片存储中是个很有用的格式,因为他能够保护截图的颜色不失真,能够很好地还原所有图片信息。然而,有许多图像应用并不提供导出较小 PNG 格式图片的功能。我们可以用 Google 发布的扩展工具 zopflipng 来解决这个问题。

注意由于 Zopfli 压缩是 CPU 密集型操作,过程中往往需要几秒钟

zopflipng 命令语法:


zopflipng [options]... infile.png outfile.png
zopflipng [options]... --prefix=[fileprefix] [files.png]...

zopflipng 命令选项:


-m: compress more: use more iterations (depending on file size)

--prefix=[fileprefix]: Adds a prefix to output filenames. May also contain a directory path. When using a prefix, multiple input files can be given and the output filenames are generated with the prefix
 If --prefix is specified without value, 'zopfli_' is used.
 If input file names contain the prefix, they are not processed but considered as output from previous runs. This is handy when using *.png wildcard expansion with multiple runs.

-y: do not ask about overwriting files.

--lossy_transparent: remove colors behind alpha channel 0. No visual difference, removes hidden information.

--lossy_8bit: convert 16-bit per channel image to 8-bit per channel.

-d: dry run: don't save any files, just see the console output (e.g. for benchmarking)

--always_zopflify: always output the image encoded by Zopfli, even if it's bigger than the original, for benchmarking the algorithm. Not good for real optimization.

-q: use quick, but not very good, compression (e.g. for only trying the PNG filter and color types)

--iterations=[number]: number of iterations, more iterations makes it slower but provides slightly better compression. Default: 15 for small files, 5 for large files.

--splitting=[0-3]: ignored, left for backwards compatibility

--filters=[types]: filter strategies to try:
 0-4: give all scanlines PNG filter type 0-4
 m: minimum sum
 e: entropy
 p: predefined (keep from input, this likely overlaps another strategy)
 b: brute force (experimental)

By default, if this argument is not given, one that is most likely the best for this image is chosen by trying faster compression with each type.
If this argument is used, all given filter types are tried with slow compression and the best result retained. A good set of filters to try is --filters=0me.

--keepchunks=nAME,nAME,...: keep metadata chunks with these names that would normally be removed, e.g. tEXt,zTXt,iTXt,gAMA, ... 
 Due to adding extra data, this increases the result size. Keeping bKGD or sBIT chunks may cause additional worse compression due to forcing a certain color type, it is advised to not keep these for web images because web browsers do not use these chunks. By default ZopfliPNG only keeps (and losslessly modifies) the following chunks because they are essential: IHDR, PLTE, tRNS, IDAT and IEND.

--keepcolortype: Keep original color type (RGB, RGBA, gray, gray+alpha or palette) and bit depth of the PNG.
 This results in a loss of compression opportunities, e.g. it will no longer convert a 4-channel RGBA image to 2-channel gray+alpha if the image only had translucent gray pixels.
 May be useful if a device does not support decoding PNGs of a particular color type.

zopflipng 命令实例:


zopflipng 优化 PNG 图片:

zopflipng input.png output.png

zopflipng 优化几个 PNG 图像并使用给定的前缀保存:

zopflipng --prefix=prefix image1.png image2.png image3.png

zopflipng 启用 -m 选项,获取更大的 PNG 压缩比:

zopflipng -m infile.png outfile.png

zopflipng 尝试所有过滤策略,以产生最好的压缩效果:

zopflipng --iterations=500 --filters=01234mepb --lossy_8bit --lossy_transparent infile.png outfile.png

zopflipng 扩展阅读:




zopflipng 命令评论