A powerful Rust image optimization CLI tool and library inspired by squoosh!.
Rimage simplifies and enhances your image optimization workflows. Optimize images effortlessly, set quality levels, and apply advanced techniques with ease. Ideal for web apps, mobile apps, and desktop software.
- Flexible Format Conversion: Supports modern image formats: JPEG, JPEG XL, PNG, AVIF, WebP.
- Quality Control: Fine-tune image quality with an intuitive interface.
- Parallel Optimization: Optimize multiple images in parallel.
- Quantization and Dithering: Advanced control for experts.
- Image Resizing: Easy resizing with the
resize
crate.
You can download latest release from the releases tab.
Alternatively you can build rimage from source if you have rust
, cargo
, nasm
and cmake
installed:
cargo install rimage
Usage: rimage [OPTIONS] <FILES>...
Arguments:
<FILES>... Input file(s) to process
Options:
-h, --help Print help
-V, --version Print version
General:
-q, --quality <QUALITY> Optimization quality [default: 75]
-f, --codec <CODEC> Image codec to use [default: mozjpeg]
-o, --output <DIR> Write output file(s) to <DIR>
-r, --recursive Saves output file(s) preserving folder structure
-s, --suffix [<SUFFIX>] Appends suffix to output file(s) names
-b, --backup Appends '.backup' to input file(s) names
Quantization:
--quantization [<QUALITY>] Enables quantization with optional quality [default: 75]
--dithering [<QUALITY>] Enables dithering with optional quality [default: 75]
Resizing:
--width <WIDTH> Resize image with specified width
--height <HEIGHT> Resize image with specified height
--filter <FILTER> Filter used for image resizing [default: lanczos3]
Note that image formats may wary from features that are used when building rimage
.
List of supported codecs with all features:
mozjpeg
,jpeg
,jpg
=> mozjpeg codecpng
=> browser png codec without compressionoxipng
=> oxipng codec with compressionjpegxl
,jxl
=> jpeg xl codecwebp
=> webp codecavif
=> avif codec
List of available resize filters:
point
=> Point resizingtriangle
=> Triangle (bilinear) resizingcatmull-rom
,catrom
=> Catmull-Rom (bicubic) resizingmitchell
=> Resize using Mitchell-Netravali filterlanczos3
=> Resize using Sinc-windowed Sinc with radius of 3
Add Rimage to your project with Cargo:
cargo add rimage
Or add this to your Cargo.toml
:
[dependencies]
rimage = "0.9.0"
use rimage::Decoder;
let path = std::path::PathBuf::from(/* Your path */);
let decoder = Decoder::from_path(&path)?;
let image = decoder.decode()?;
// Handle the image...
use rimage::{rgb::RGBA8, Encoder, Image, config::{EncoderConfig, Codec}};
let image_data = vec![RGBA8::new(0, 0, 0, 0); 100 * 50];
let image = Image::new(image_data, 100, 50);
let config = EncoderConfig::new(Codec::MozJpeg).with_quality(80.0).unwrap();
let file = std::fs::File::create("output.jpg").expect("Failed to create file");
let encoder = Encoder::new(file, image).with_config(config);
encoder.encode()?; // Writes image data to the file.
For full API documentation, visit docs.rs page.
Read the contribution guide for build instructions and guidelines.
Rimage is dual-licensed under Apache License 2.0 and MIT License. You can choose either license for your use.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
View the Changelog for version-specific changes.