Skip to content
/ oxipng Public
forked from shssoichiro/oxipng

Multithreaded PNG optimizer written in Rust

License

Notifications You must be signed in to change notification settings

negge/oxipng

 
 

Repository files navigation

Oxipng

Build Status Version License Docs

Overview

Oxipng is a multithreaded lossless PNG compression optimizer. It can be used via a command-line interface or as a library in other Rust programs.

Installing

Oxipng for Windows can be downloaded from the Releases link on the GitHub page.

For MacOS or Linux, it is recommended to install from your distro's package repository, if possible.

Alternatively, oxipng can be installed from Cargo, via the following command:

cargo install oxipng

Oxipng can be built from source using the latest stable or nightly Rust. This is primarily useful for developing on oxipng.

git clone https://github.com/shssoichiro/oxipng.git
cd oxipng
cargo build --release
cp target/release/oxipng /usr/local/bin

The current minimum supported Rust version is 1.56.0.

Oxipng follows Semantic Versioning.

Usage

Oxipng is a command-line utility. Basic usage looks similar to the following:

oxipng -o 4 -i 1 --strip safe *.png

The most commonly used options are as follows:

  • Optimization: -o 1 through -o 6, lower is faster, higher is better compression. The default (-o 2) is sufficiently fast on a modern CPU and provides 30-50% compression gains over an unoptimized PNG. -o 4 is 6 times slower than -o 2 but can provide 5-10% extra compression over -o 2. Using any setting higher than -o 4 is unlikely to give any extra compression gains and is not recommended.
  • Interlacing: -i 1 will enable Adam7 PNG interlacing on any images that are processed. -i 0 will remove interlacing from all processed images. Not specifying either will keep the same interlacing state as the input image. Note: Interlacing can add 25-50% to the size of an optimized image. Only use it if you believe the benefits outweigh the costs for your use case.
  • Strip: Used to remove metadata info from processed images. Used via --strip [safe,all]. Can save a few kilobytes if you don't need the metadata. "Safe" removes only metadata that will never affect rendering of the image. "All" removes all metadata that is not critical to the image. You can also pass a comma-separated list of specific metadata chunks to remove. -s can be used as a shorthand for --strip safe.

More advanced options can be found by running oxipng -h.

Library Usage

Although originally intended to be used as an executable, oxipng can also be used as a library in other Rust projects. To do so, simply add oxipng as a dependency in your Cargo.toml, then extern crate oxipng in your project. You should then have access to all of the library functions documented here. The simplest method of usage involves creating an Options struct and passing it, along with an input filename, into the optimize function.

History