Linux command
pngquant 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Compress PNG with quality range
pngquant --quality=[65-80] [image.png]
Compress to specific output file
pngquant [image.png] -o [output.png]
Compress and overwrite original
pngquant --ext=.png --force [image.png]
Compress with specific color count
pngquant [256] [image.png]
Compress multiple files
pngquant [*.png]
Compress with maximum quality
pngquant --quality=[90-100] [image.png]
Skip if quality cannot be met
pngquant --skip-if-larger [image.png]
Output to stdout
pngquant - < [input.png] > [output.png]
说明
pngquant compresses PNG images by reducing the number of colors using lossy quantization. It converts 24/32-bit PNG to 8-bit palette PNG, dramatically reducing file size while maintaining visual quality. The algorithm uses median-cut quantization with dithering to hide color reduction artifacts. Quality settings control how aggressively colors are reduced - higher quality preserves more detail but produces larger files. Quality range (e.g., 65-80) sets minimum acceptable quality. If the minimum cannot be achieved, pngquant exits without writing (exit code 99). This prevents unacceptably degraded images. Speed setting trades processing time for output quality. Slower speeds find better color palettes. For automated pipelines, moderate speeds (3-4) offer good balance. The tool excels at compressing graphics, icons, and images with limited colors. Photographs may show more visible quality loss due to the 256-color limit.
参数
- --quality _MIN_-_MAX_
- Quality range (0-100). Skip if quality below MIN.
- -o, --output _FILE_
- Output file name.
- --ext _SUFFIX_
- Set output filename suffix (default: -or8.png or -fs8.png depending on dithering).
- -f, --force
- Overwrite existing files.
- -s _N_, --speed _N_
- Speed/quality tradeoff (1=slowest/best, 10=fastest; default 3).
- --skip-if-larger
- Don't write if output larger than input.
- --strip
- Remove metadata.
- --posterize _BITS_
- Reduce precision of color channels.
- --nofs
- Disable Floyd-Steinberg dithering.
- --floyd=_LEVEL_
- Set dithering level (0.0-1.0).
- -v, --verbose
- Verbose output.
- -
- Read from stdin, write to stdout.
FAQ
What is the pngquant command used for?
pngquant compresses PNG images by reducing the number of colors using lossy quantization. It converts 24/32-bit PNG to 8-bit palette PNG, dramatically reducing file size while maintaining visual quality. The algorithm uses median-cut quantization with dithering to hide color reduction artifacts. Quality settings control how aggressively colors are reduced - higher quality preserves more detail but produces larger files. Quality range (e.g., 65-80) sets minimum acceptable quality. If the minimum cannot be achieved, pngquant exits without writing (exit code 99). This prevents unacceptably degraded images. Speed setting trades processing time for output quality. Slower speeds find better color palettes. For automated pipelines, moderate speeds (3-4) offer good balance. The tool excels at compressing graphics, icons, and images with limited colors. Photographs may show more visible quality loss due to the 256-color limit.
How do I run a basic pngquant example?
Run `pngquant --quality=[65-80] [image.png]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --quality _MIN_-_MAX_ do in pngquant?
Quality range (0-100). Skip if quality below MIN.