Oxipng is a powerful, multithreaded lossless PNG/APNG compression optimizer. It can be used via a command-line interface or as a library in other Rust programs, making it a versatile tool for developers and users who need efficient image optimization.
Oxipng excels in compressing images without any loss of quality, providing a significant reduction in file size. This makes it particularly useful for web developers and anyone looking to optimize images for faster loading times and reduced bandwidth usage.
Oxipng can be installed on various operating systems, including Windows, MacOS, and Linux. Here are some installation methods:
Download the latest release from the Releases page on GitHub.
Install from your distribution's package repository if available. For example:
Alternatively, install Oxipng using Cargo, Rust's package manager:
To build Oxipng from source, you need the latest stable or nightly Rust:
Oxipng is primarily a command-line utility. Here's an example command to optimize images for web use:
-o 0
to -o 6
(or -o max
). Higher levels provide better compression but take longer. The default is -o 2
.--strip [safe,all]
removes metadata to save space. -s
can be used as a shorthand for --strip safe
.--alpha
optimizes images with transparency, altering the color values of fully transparent pixels for better compression.For a full list of options, run:
Integrate Oxipng into your Git workflow using [pre-commit]:
[Trunk] is an extendable superlinter that can use Oxipng to optimize PNG files in a Git repository:
For more detailed setup instructions, refer to the Trunk documentation.
Oxipng can also be used as a library in other Rust projects. Add it to your Cargo.toml
:
Then, use it in your project:
For more information, refer to the Oxipng library documentation.
Oxipng has been benchmarked against OptiPNG, demonstrating significantly faster performance. Here are some benchmark results:
Benchmark 1: ./target/release/oxipng -P ./tests/files/rgb_16_should_be_grayscale_8.png
Time (mean ± σ): 59.6 ms ± 7.7 ms [User: 77.4 ms, System: 3.6 ms]
Range (min … max): 53.3 ms … 89.9 ms 32 runs
Benchmark 2: optipng -simulate ./tests/files/rgb_16_should_be_grayscale_8.png
Time (mean ± σ): 132.4 ms ± 0.8 ms [User: 132.5 ms, System: 0.6 ms]
Range (min … max): 131.8 ms … 134.4 ms 22 runs
Summary
./target/release/oxipng -P ./tests/files/rgb_16_should_be_grayscale_8.png ran
2.22 ± 0.29 times faster than optipng -simulate ./tests/files/rgb_16_should_be_grayscale_8.png
For more benchmark results and details, visit the Oxipng GitHub repository.
Oxipng began as a rewrite of the OptiPNG project, focusing on adding multithreading support and utilizing Rust for a more modern and safer codebase. While similar, Oxipng is not a drop-in replacement for OptiPNG.