Expand description
§Rimage
Rimage is a powerful Rust image optimization library extending zune_image crate. Designed to enhance your image optimization workflows.
§Features
- Modern codecs:
- Rimage uses modern codecs optimized to produce tiny images
- Under the hood uses
zune_imagecrate that enhances performance
- Optimization operations:
- Rimage provides several image optimization operation
- Resize - uses
fast_image_resizecrate that has incredible performance - Quantization - allowing to reduce image palette
§Formats
| Image Format | Decoder | Encoder |
|---|---|---|
| jpeg | - | mozjpeg |
| png | - | oxipng |
| avif | libavif | ravif |
| webp | webp | webp |
§Usage
This library is a extension for zune_image crate. For proper usage you will need to install it along with zune_core.
§Decoders
use std::fs::File;
use rimage::codecs::avif::AvifDecoder;
use zune_image::image::Image;
let file_content = File::open(path).unwrap();
let mut decoder = AvifDecoder::try_new(file_content).unwrap();
let img = Image::from_decoder(decoder).unwrap();
zune_imagecurrently doesn’t support custom decoders forreadmethod. So for decoding you will need hacky approach to satisfy the compiler.
§Encoders
With default options
use rimage::codecs::mozjpeg::MozJpegEncoder;
use zune_image::traits::EncoderTrait;
let mut encoder = MozJpegEncoder::new();
let mut result: Vec<u8> = vec![];
encoder.encode(&img, &mut result).unwrap();With custom options
use rimage::codecs::mozjpeg::{MozJpegOptions, MozJpegEncoder};
use zune_image::traits::EncoderTrait;
let options = MozJpegOptions {
quality: 80.,
..Default::default()
};
let mut encoder = MozJpegEncoder::new_with_options(options);
let mut result: Vec<u8> = vec![];
encoder.encode(&img, &mut result).unwrap();Note that some codecs have own implementation of options, check their documentation to learn more
§Operations
Resize
use rimage::operations::resize::{Resize, ResizeAlg};
use zune_image::traits::OperationsTrait;
let resize = Resize::new(100, 100, ResizeAlg::Nearest);
resize.execute(&mut img).unwrap();Check
fast_image_resizedocumentation to learn more about resize algorithms
Quantize
use rimage::operations::quantize::Quantize;
use zune_image::traits::OperationsTrait;
let quantize = Quantize::new(75, None); // without dithering
quantize.execute(&mut img).unwrap();Modules§
- codecs
- All additional codecs for the zune_image
- operations
- All additional operations for the zune_image