
Oxipng
CLI多线程的无损 PNG 压缩工具,批量缩小截图、切图和图标的体积而不损画质,还能去掉无用的元数据,适合设计师交付切图或网页上线前压缩图片。macOS 可用 Homebrew 安装。
Oxipng
Overview
Oxipng is a multithreaded lossless PNG/APNG compression optimizer. It can be used via a command-line interface or as a library in other Rust programs. It is fast and highly effective.
Installing
Oxipng for Windows can be downloaded via the Releases section on its GitHub page. Recently, however, Oxipng has also been made available through package managers. Check the list below for up-to-date options.
For MacOS or Linux, it is recommended to install from your distro's package repository, provided Oxipng is available there in a not too outdated version for your use case.
Oxipng is known to be packaged for the environments listed below.
Alternatively, Oxipng can be installed from Cargo, via the following command:
cargo install oxipng
Oxipng can also be built from source using the latest stable or nightly Rust. This is primarily useful for developing on Oxipng.
git clone https://github.com/oxipng/oxipng.git
cd oxipng
cargo build --release
cp target/release/oxipng /usr/local/bin
The current minimum supported Rust version is 1.85.1.
Oxipng follows Semantic Versioning.
Usage
Oxipng is a command-line utility. An example usage, suitable for web, may be the following:
oxipng -o 4 --strip safe --alpha *.png
The most commonly used options are as follows:
- Optimization:
-o 0through-o 6(or-o max), lower is faster, higher is better compression. The default (-o 2) is quite fast and provides good compression. Higher levels can be notably better* but generally have increasingly diminishing returns. - 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.-scan be used as a shorthand for--strip safe. - Alpha:
--alphacan improve compression of images with transparency, by altering the color values of fully transparent pixels. This is generally recommended, but take care as this is technically a lossy transformation and may be unsuitable for some specific applications.
More advanced options can be found by running oxipng --help, or viewed here.
Some options have both short (-a) and long (--alpha) forms. Which form you use is just a
matter of preference. Multiple short options can be combined together, e.g.:
-savvo6 is equivalent to to --strip safe --alpha --verbose --verbose --opt 6.
All options are case-sensitive.
* Note that oxipng is not a brute-force optimizer. This means that while higher optimization levels
are almost always better or equal to lower levels, this is not guaranteed and it is possible in
rare circumstances that a lower level may give a marginally smaller output. Similarly, using Zopfli
compression (-z) is not guaranteed to always be better than default compression.
APNG support
Oxipng currently only supports limited optimization of animated PNGs (APNGs). It can perform alpha-optimization, refiltering and recompression of all frames, but all transformations will be disabled. For best results, it is recommended to use another tool such as apngopt before running Oxipng.
Git integration via pre-commit
Create a .pre-commit-config.yaml file like this, or add the lines after the repos map
preamble to an already existing one:
repos:
- repo: https://github.com/oxipng/oxipng
rev: v10.0.0
hooks:
- id: oxipng
args: ["-o", "4", "--strip", "safe", "--alpha"]
Docker
A Docker image is availlable at ghcr.io/oxipng/oxipng for linux/amd64 and linux/arm64.
You can use it the following way:
docker run --rm -v $(pwd):/work ghcr.io/oxipng/oxipng -o 4 /work/file.png
Some older images are also available at ghcr.io/shssoichiro/oxipng.
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. 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.
It is recommended to disable the "binary" feature when including Oxipng as a library. Currently, there is
no simple way to just disable one feature in Cargo, it has to be done by disabling default features
and specifying the desired ones, for example:
oxipng = { version = "10.0", features = ["parallel", "zopfli", "filetime"], default-features = false }
Software using Oxipng
- ImageOptim: Mac app and web service for optimizing images
- Squoosh: Web app for optimizing images
- FileOptimizer: Windows app for optimizing files
- Curtail: Linux app for optimizing images
- pyoxipng: Python wrapper for Oxipng
- jSquash: Collection of WebAssembly image codecs
- Trunk: Developer experience toolkit for managing code
History
Oxipng began in 2015 as a rewrite of the OptiPNG project. The core goal was to implement multithreading, which would have been 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).
However, Oxipng has evolved considerably since then. While some of the options remain similar to OptiPNG, the architecture and capabilities are now quite different. It is not a drop-in replacement - if you are migrating from OptiPNG, please check the help before use.
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.
Benchmarks
An independent benchmark is linked here with permission by the author:
oxipng and friends: A comparison of PNG optimization tools
License
Oxipng is open-source software, distributed under the MIT license.
相關資源

VTracer
CLI把 JPG、PNG 等位图转成 SVG 矢量图的命令行工具,支持彩色描摹、黑白线稿和光照不均的扫描件,适合把 logo、插画和扫描的旧图纸矢量化。命令行版目前是 1.0 预览版,用 cargo 安装,需要 Rust 环境;也提供桌面版。
visioncortex/vtracer7.3k
pngquant
CLI有损 PNG 压缩命令行工具:把图片转成保留透明通道的 8 位 PNG,体积通常缩小 60%–80%,可整批压缩并设定质量区间,适合给公众号配图、课件插图和网页切图瘦身。macOS 可用 Homebrew 安装,无需账号。
kornelski/pngquant5.8k
resvg
CLI高保真 SVG 渲染库与命令行工具,可把 SVG 图标、插画按指定尺寸导出为 PNG,适合批量切图;不依赖系统库,各平台渲染结果逐像素一致。不支持 SVG 动画,安装需要 Rust 环境(cargo),也可从 Releases 下载 macOS 预编译版。
linebender/resvg4.1k
Web Asset Generator
Skill从 logo、文字或 emoji 一键生成网站 favicon、PWA 应用图标和各社交平台的分享预览图(Open Graph),自动出齐全部尺寸并检查文字对比度,还能把对应代码加进网页项目。需要本机 Python 与 Pillow。
alonw0/web-asset-generator518
Rembg
CLI一条命令去除图片背景:支持单张、整个文件夹批处理和监听目录,可只输出蒙版、切换 U2Net、SAM 等模型,也能启动 HTTP 服务或配合 FFmpeg 处理视频帧。默认模型在本地推理。
danielgatis/rembg25.1k
BackgroundRemover
CLI用 AI 一条命令去除图片和视频的背景:支持整个文件夹批处理、人像专用模型、边缘精修和换纯色底,视频可输出透明底 MOV 或叠加到新背景上,适合处理商品图、证件照和短视频素材。模型在本地运行,需先安装 PyTorch 与 ffmpeg,首次运行会自动下载模型。
nadermx/backgroundremover8.1k