Oxipng

用 Rust 编写的多线程 PNG 优化器。「Multithreaded PNG optimizer written in Rust」

  • Owner: oxipng/oxipng
  • Platform: Linux, Mac, Windows
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Oxipng

概述

Oxipng 是一个多线程的无损 PNG 压缩优化器,它可以通过命令行接口或作为其他 Rust 程序的库使用。它可以通过命令行界面或作为其他 Rust 程序的库来使用。

安装

Oxipng for Windows 可以从 GitHub 页面的 Releases 链接下载。

对于 MacOS 或 Linux,如果可能的话,建议从发行版的包库中安装。

另外,也可以通过以下命令从 Cargo 安装 oxipng。

cargo install oxipng

Oxipng 可以使用最新的稳定版或夜间的 Rust 从源代码构建。这主要是对在 oxipng 上开发有用。

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

目前支持的最低 Rust 版本是 1.41.0。

Oxipng 遵循 Semantic Versioning。

使用方法

Oxipng 是一个命令行工具。基本使用方法类似于下面。

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

最常用的选项如下。

  • 优化:-o 1 至 -o 6,越低越快,越高越好压缩。默认值(-o 2)在现代 CPU 上足够快,比未优化的 PNG 提供 30-50% 的压缩收益。-使用任何高于 -o 4 的设置都不可能带来任何额外的压缩收益,因此不推荐使用。
  • 隔行扫描:-i 1 将在处理的任何图像上启用 Adam7 PNG 隔行扫描。-i 0 将从所有处理过的图像中移除交错。不指定任何一个,将保持与输入图像相同的交错状态。注意:隔行扫描会使优化后的图像大小增加 25-50%。只有当你认为对于你的使用案例来说,它的好处大于成本时才会使用。
  • 剥离。用于从处理后的图像中移除元数据信息。通过 --strip [safe,all] 使用。如果你不需要元数据,可以节省几千字节。"safe" 只删除不会影响图像渲染的元数据。"All" 则会删除所有对图像不重要的元数据。你也可以传递一个以逗号分隔的要删除的特定元数据块的列表。-s 可以作为 -strip safe 的简写。

更多高级选项可以通过运行 oxipng -h 找到。

库使用情况

虽然最初的目的是作为一个可执行文件使用,但 oxipng 也可以在其他 Rust 项目中作为一个库使用。要做到这一点,只需在您的 Cargo.toml 中添加 oxipng 作为依赖,然后在您的项目中 extern crate oxipng。然后,您应该可以访问这里文档中的所有库函数。最简单的使用方法是创建一个 Options 结构,并将它和一个输入文件名一起传递到优化函数中。

历程

Oxipng 最初是对 OptiPNG 项目的彻底重写,由于自2014年3月以来没有人对其进行过提交,因此被认为已经死亡。(OptiPNG 在 Oxipng 首次发布后,已经发布了新的版本。)为了避免混淆和潜在的法律问题,改了名字。

重写 OptiPNG 的核心目标是实现多线程,这在 OptiPNG 现有的 C 代码库中是很难做到的。这也是选择更现代、更安全的语言(Rust)的一个机会。

贡献

欢迎任何贡献,并将通过 GitHub 上的 pull request 接受。错误报告可以通过 GitHub 问题提交。请尽可能多地包含细节。如果你有能力在提交bug报告的同时提交修复,最好通过 pull request 提交,但你不需要是 Rust 开发者也能做出贡献。其他的贡献(例如改进文档或翻译)也欢迎通过 GitHub 来完成。

许可证

Oxipng 是一个开源软件,采用 MIT 许可发布。

基准

在 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz 与 8 个逻辑核心上,对 OptiPNG 0.7.7 版进行了 oxipng 3.0.1 (在 rustc 1.45.0 (5c1f21c3b 2020-07-13) 上编译)的测试。

Benchmark #1: ./target/release/oxipng -P ./tests/files/rgb_16_should_be_grayscale_8.png
  Time (mean ± σ):     101.6 ms ±   5.9 ms    [User: 261.6 ms, System: 16.5 ms]
  Range (min … max):    94.7 ms … 113.3 ms    28 runs
 
Benchmark #2: optipng -simulate ./tests/files/rgb_16_should_be_grayscale_8.png
  Time (mean ± σ):     294.0 ms ±   3.5 ms    [User: 293.5 ms, System: 0.6 ms]
  Range (min … max):   290.4 ms … 300.5 ms    10 runs
 
Summary
  './target/release/oxipng -P ./tests/files/rgb_16_should_be_grayscale_8.png' ran
    2.89 ± 0.17 times faster than 'optipng -simulate ./tests/files/rgb_16_should_be_grayscale_8.png'



Benchmark #1: ./target/release/oxipng -o4 -P ./tests/files/rgb_16_should_be_grayscale_8.png
  Time (mean ± σ):     131.6 ms ±   6.1 ms    [User: 509.8 ms, System: 17.1 ms]
  Range (min … max):   123.5 ms … 143.6 ms    23 runs
 
Benchmark #2: optipng -o 4 -simulate ./tests/files/rgb_16_should_be_grayscale_8.png
  Time (mean ± σ):     995.7 ms ±   8.0 ms    [User: 993.6 ms, System: 1.7 ms]
  Range (min … max):   987.5 ms … 1012.8 ms    10 runs
 
Summary
  './target/release/oxipng -o4 -P ./tests/files/rgb_16_should_be_grayscale_8.png' ran
    7.57 ± 0.35 times faster than 'optipng -o 4 -simulate ./tests/files/rgb_16_should_be_grayscale_8.png'


Main metrics

Overview
Name With Owneroxipng/oxipng
Primary LanguageRust
Program languageRust (Language Count: 3)
PlatformLinux, Mac, Windows
License:MIT License
所有者活动
Created At2016-01-11 15:45:39
Pushed At2025-06-23 23:38:44
Last Commit At2025-06-24 01:38:43
Release Count82
Last Release Namev9.1.5 (Posted on )
First Release Namev0.1.0 (Posted on )
用户参与
Stargazers Count3.3k
Watchers Count20
Fork Count132
Commits Count874
Has Issues Enabled
Issues Count256
Issue Open Count31
Pull Requests Count425
Pull Requests Open Count0
Pull Requests Close Count25
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Oxipng

Build Status
Version
License

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 can be downloaded from the Releases link on the GitHub page.

Oxipng can also be installed from Cargo, via the following command:

cargo install oxipng

Alternatively, oxipng can be built from source using the latest stable or nightly Rust:

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.36.0. Oxipng may compile on earlier versions of Rust,
but there is no guarantee.

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

Oxipng began as a complete rewrite of the OptiPNG project,
which was assumed to be dead as no commit had been made to it since March 2014.
(OptiPNG has since released a new version, after Oxipng was first released.)
The name has been changed to avoid confusion and potential legal issues.

The core goal of rewriting OptiPNG was to implement multithreading,
which would be very difficult to do within the existing C codebase of OptiPNG.
This also served as an opportunity to choose a more modern, safer language (Rust).

Contributing

Any contributions are welcome and will be accepted via pull request on GitHub. Bug reports can be
filed via GitHub issues. Please include as many details as possible. If you have the capability
to submit a fix with the bug report, it is preferred that you do so via pull request,
however you do not need to be a Rust developer to contribute.
Other contributions (such as improving documentation or translations) are also welcome via GitHub.

License

Oxipng is open-source software, distributed under the MIT license.

Benchmarks

Tested oxipng 2.3.0 (compiled on rustc 1.38.0 (625451e37 2019-09-23)) against OptiPNG version 0.7.7 on Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz with 8 logical cores


Benchmark #1: ./target/release/oxipng -P ./tests/files/rgb_16_should_be_grayscale_8.png
  Time (mean ± σ):      92.4 ms ±   2.7 ms    [User: 249.4 ms, System: 14.5 ms]
  Range (min … max):    88.4 ms …  98.5 ms    31 runs
 
Benchmark #2: optipng -simulate ./tests/files/rgb_16_should_be_grayscale_8.png
  Time (mean ± σ):     273.5 ms ±   1.7 ms    [User: 272.4 ms, System: 1.2 ms]
  Range (min … max):   270.3 ms … 275.1 ms    10 runs
 
Summary
  './target/release/oxipng -P ./tests/files/rgb_16_should_be_grayscale_8.png' ran
    2.96 ± 0.09 times faster than 'optipng -simulate ./tests/files/rgb_16_should_be_grayscale_8.png'



Benchmark #1: ./target/release/oxipng -o4 -P ./tests/files/rgb_16_should_be_grayscale_8.png
  Time (mean ± σ):     120.7 ms ±   4.1 ms    [User: 486.3 ms, System: 14.8 ms]
  Range (min … max):   113.7 ms … 130.0 ms    23 runs
 
Benchmark #2: optipng -o 4 -simulate ./tests/files/rgb_16_should_be_grayscale_8.png
  Time (mean ± σ):     916.8 ms ±   7.4 ms    [User: 914.8 ms, System: 1.7 ms]
  Range (min … max):   906.8 ms … 929.9 ms    10 runs
 
Summary
  './target/release/oxipng -o4 -P ./tests/files/rgb_16_should_be_grayscale_8.png' ran
    7.59 ± 0.26 times faster than 'optipng -o 4 -simulate ./tests/files/rgb_16_should_be_grayscale_8.png'