LinuxCommandLibrary

oxipng

Optimize PNG image file size

TLDR

Compress a PNG file (overwrites the file by default)

$ oxipng [path/to/file.png]
copy

Compress a PNG file and save the output to a new file
$ oxipng --out [path/to/output.png] [path/to/file.png]
copy

Compress all PNG files in the current directory using multiple threads
$ oxipng "*.png"
copy

Compress a file with a set optimization level (default is 2)
$ oxipng --opt [0|1|2|3|4|5|6|max] [path/to/file.png]
copy

Set the PNG interlacing type (0 removes interlacing, 1 applies Adam7 interlacing, keep preserves existing interlacing; default is 0)
$ oxipng --interlace [0|1|keep] [path/to/file.png]
copy

Perform additional optimization on images with an alpha channel
$ oxipng --alpha [path/to/file.png]
copy

Use the much slower but stronger Zopfli compressor with max optimization
$ oxipng --zopfli --opt max [path/to/file.png]
copy

Strip all non-critical metadata chunks
$ oxipng --strip all [path/to/file.png]
copy

SYNOPSIS

oxipng [options] <files>...
oxipng --help
oxipng --version

PARAMETERS

-o, --opt <level>
    Sets the optimization level from 0 (no compression) to 6 (full compression). Higher levels take longer but compress more. Default is 2.

-i, --interlace <0|1>
    Sets the interlace method (0: no interlace, 1: Adam7 interlacing).

-Z, --strip <safe|all>
    Removes metadata chunks from the PNG. safe preserves color profiles (sRGB, iCCP), while all removes everything possible.

-s, --stdout
    Writes the optimized image to standard output instead of a file.

-f, --force
    Overwrites existing output files without prompting for confirmation.

-t, --threads <count>
    Specifies the number of threads to use for optimization. Set to 0 to use all available CPU cores.

-z, --force-zopfli
    Forces the use of Zopfli compression, which is slower but typically achieves better compression ratios.

-v, --verbose
    Enables verbose output, showing more details about the optimization process and savings.

-a, --alpha
    Attempts to optimize the alpha channel by removing unused alpha or simplifying transparency where possible.

-P, --preserve
    Preserves file permissions and timestamps of the original file after optimization.

DESCRIPTION

oxipng is a modern, high-performance PNG optimizer written in Rust. Its primary goal is to reduce the file size of PNG images without any loss of quality, making it a truly lossless compression tool. It achieves this by applying various sophisticated optimization techniques, including different deflate compression strategies, intelligent filter choices, and bit depth reductions where possible. A key feature of oxipng is its ability to efficiently utilize multiple CPU cores for parallel processing, significantly speeding up optimization, especially for batches of images or very large files. It supports various optimization levels, allowing users to balance compression thoroughness against processing time. It's a popular choice for web developers, designers, and anyone looking to optimize image assets efficiently for web delivery or storage.

CAVEATS

oxipng performs lossless optimization only; it will not convert image formats or apply lossy compression. While generally very fast, using the --force-zopfli option can significantly increase processing time for potentially better compression. For very large images or high optimization levels, memory consumption can be noticeable.

DEFAULT BEHAVIOR

By default, oxipng overwrites the original file with the optimized version and uses an optimization level of 2. This level provides a good balance between compression effectiveness and processing speed.

BATCH PROCESSING

oxipng is highly efficient for optimizing multiple PNG files simultaneously. It automatically utilizes available CPU cores when processing a list of files, making it ideal for optimizing entire directories of images.

HISTORY

oxipng is a relatively modern utility, written in Rust, which differentiates it from older PNG optimizers by leveraging Rust's performance and concurrency features. It was developed to provide a fast, multi-threaded alternative to existing tools like optipng and pngcrush, focusing on efficient lossless compression for contemporary computing environments.

SEE ALSO

optipng(1), pngcrush(1), zopfli(1), gifsicle(1), jpegoptim(1)

Copied to clipboard