pngquant is a command-line utility and a library for lossy compression of PNG images.
The conversion reduces file sizes significantly (often as much as 70%) and preserves full alpha transparency. Generated images are compatible with all web browsers and operating systems.
You can install it with:
wapm install -g pngquant
- batch conversion of multiple files:
- Unix-style stdin/stdout chaining:
… | pngquant - | …
- High-quality palette generation
- advanced quantization algorithm with support for gamma correction and premultiplied alpha
- unique dithering algorithm that does not add unnecessary noise to the image
- Configurable quality level
- automatically finds required number of colors and can skip images which can't be converted with the desired quality
- Fast, modern code
- based on a portable libimagequant library
- C99 with no workarounds for legacy systems or compilers (apart from Visual Studio)
- multicore support (via OpenMP) and Intel SSE optimizations
pngquant -h for full list.
max are numbers in range 0 (worst) to 100 (perfect), similar to JPEG. pngquant will use the least amount of colors required to meet or exceed the
max quality. If conversion results in quality below the
min quality the image won't be saved (if outputting to stdin, 24-bit original will be output) and pngquant will exit with status code 99.
pngquant --quality=65-80 image.png
Set custom extension (suffix) for output filename. By default
-fs8.png is used. If you use
--ext=.png --force options pngquant will overwrite input files in place (use with caution).
-o out.png or
Writes converted file to the given path. When this option is used only single input file is allowed.
Don't write converted files if the conversion isn't worth it.
Speed/quality trade-off from 1 (slowest, highest quality, smallest files) to 11 (fastest, less consistent quality, light comperssion). The default is 4. It's recommended to keep the default, unless you need to generate images in real time (e.g. map tiles). Higher speeds are fine with 256 colors, but don't handle lower number of colors well.
Disables Floyd-Steinberg dithering.
Controls level of dithering (0 = none, 1 = full). Note that the
= character is required.
Reduce precision of the palette by number of bits. Use when the image will be displayed on low-depth screens (e.g. 16-bit displays or compressed textures in ARGB444 format).
Don't copy optional PNG chunks. Metadata is always removed on Mac (when using Cocoa reader).
See man page (
man pngquant) for the full list of options.
This version of pngquant is built using v2.8.0 of pngquant. Original configure script needs to be patched in order to be used by emscripten. Patched version of this file is present in the deps folder in this directory. Additionally, patch file for configure script is also present in the repository in order to create a fresh copy. Build script assumes that emscripten is already built and available in the system path. Once this is ensured, just run
./build.sh which will initiate build process and pngquant. will be available in dist folder.
pngquant is dual-licensed:
Under GPL v3 or later with an additional copyright notice that must be kept for the older parts of the code.