oxipng
A multithreaded lossless PNG optimizer written in Rust — shrinks PNG files with no quality loss.
oxipng is a multithreaded lossless PNG optimizer. It reduces the file size of
PNG images by trying different compression strategies and filter combinations,
keeping whichever produces the smallest output — with no change to the image's
appearance whatsoever.
It is a Rust reimplementation and significant improvement over the classic
optipng tool, with parallelism, better compression ratios, and support for
modern PNG features like stripping unnecessary metadata.
Features
- Lossless — pixel data is never altered; only the compressed representation is optimised
- Multithreaded — processes multiple files in parallel and tries compression strategies concurrently
- Better than optipng — consistently produces smaller files than its C predecessor
- Metadata stripping — removes unnecessary chunks (Exif, ICC profiles, text comments) that bloat file size
- Interlace control — convert between interlaced and non-interlaced PNG
- Transparency optimisation — can fix "dirty transparent" pixels to improve compressibility
- Bit depth reduction — optionally reduces colour depth when the image content allows it
- Preserve or strip colour profiles — fine-grained control over which PNG chunks to keep
Installation
cargo install oxipng
Or via your system package manager:
# Debian / Ubuntu
apt install oxipng
# Fedora
dnf install oxipng
# Arch Linux
pacman -S oxipng
# macOS
brew install oxipng
# Nix
nix-env -iA nixpkgs.oxipngUsage
# Optimise a single file in-place
oxipng image.png
# Optimise multiple files
oxipng *.png
# Optimise recursively in a directory
oxipng --recursive images/
# Set the optimisation level (0–6, default is 2; higher = smaller but slower)
oxipng -o 4 image.png
# Maximum compression (equivalent to -o 6 with extra options — slow but thorough)
oxipng -o max image.png
# Strip all non-critical metadata chunks (recommended for web)
oxipng --strip all image.png
# Strip only safe metadata (preserves colour profile)
oxipng --strip safe image.png
# Write output to a new file instead of overwriting
oxipng image.png --out optimised.png
# Preview how much would be saved without modifying files
oxipng --pretend image.png
# Optimise and fix dirty transparent pixels
oxipng --alpha image.pngOptimisation levels
| Level | Speed | Compression |
|---|---|---|
0 | Fastest | Minimal |
2 | Fast (default) | Good |
4 | Moderate | Better |
6 | Slow | Best built-in |
max | Very slow | Maximum (tries everything) |
For most workflows, -o 4 --strip safe is a good balance between compression
and speed. For a one-time batch optimisation of an image library,
-o max --strip all is worth the wait.
Typical savings
On a typical set of PNG screenshots or UI assets, oxipng at -o 4 commonly
achieves 10–30% size reduction with zero visual difference. Files that were
already processed by other optimisers can still often be reduced further.
CI / build pipeline integration
oxipng is well-suited to running in CI to keep image assets lean:
# Fail if any PNG can be reduced by more than 1%
oxipng --pretend --quiet images/*.png
Or as a pre-commit step to automatically optimise any PNG added to the repository.