我对此图像和 ImageMagick 进行了一些实验,该图像包含在大多数 Linux 发行版中,可用于 macOS 和 Windows。
首先是原始图像,然后通过抖动减少到 16 色,然后在没有抖动的情况下减少到 16 色。
使用抖动:
convert paddington.png -colors 16 d.png
没有抖动:
convert paddington.png +dither -colors 16 e.png
然后我查看了 ImageMagick 生成的图像,它们都有 8bpp!所以,我尝试使用 "venerable" NetPBM 套件,发现它会创建一个 4bpp 图像,看起来像这样:
convert paddington.png +dither -colors 16 ppm:- | pnmtopng > result.png
如果我在上面运行pngcheck,它在我看来就像一个 4bpp PNG:
pngcheck -vv result.png
输出
File: result.png (4857 bytes)
chunk IHDR at offset 0x0000c, length 13
150 x 150 image, 4-bit palette, non-interlaced
chunk PLTE at offset 0x00025, length 48: 16 palette entries
chunk IDAT at offset 0x00061, length 4740
zlib: deflated, 16K window, default compression
row filters (0 none, 1 sub, 2 up, 3 avg, 4 paeth):
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
(150 out of 150)
chunk IEND at offset 0x012f1, length 0
No errors detected in result.png (4 chunks, 56.8% compression).
目前,我建议您考虑“全力以赴”以使用 ImageMagick 和 NetPBM。