Crate rimage

source ·
Expand description

Rimage

Rimage is a powerful Rust image optimization library designed to simplify and enhance your image optimization workflows. With Rimage, you can effortlessly optimize images for various formats, set quality levels, and apply advanced image optimization techniques with ease. Whether you’re building a web application, mobile app, or desktop software, Rimage empowers you to deliver visually stunning content with minimal effort.

Features

  1. Flexible Format Conversion: Rimage supports all modern image formats, including JPEG, JPEG XL, PNG, AVIF, and WebP.
  2. Quality Control: Fine-tune the quality of your images using a simple and intuitive interface.
  3. Parallel Optimization: Harness the power of parallel processing to optimize multiple images simultaneously.
  4. Quantization and Dithering: For advanced users, Rimage offers control over quantization and dithering.
  5. Image Resizing: Resize images with ease using resize crate.

Decoding

From path:

use rimage::Decoder;

let path = std::path::PathBuf::from("tests/files/jpg/f1t.jpg");

let decoder = Decoder::from_path(&path)?;

let image = decoder.decode()?;

// do something with the image data...

From memory:

use rimage::{Decoder, config::ImageFormat};

let reader = std::io::BufReader::new(f); // you can use any reader

let decoder = Decoder::new(reader).with_format(ImageFormat::Jpeg);

let image = decoder.decode()?;

// do something with the image data...

Encoding

use std::fs::File;

use rimage::{rgb::RGBA8, Encoder, config::{EncoderConfig, Codec}};
use image::{RgbaImage, DynamicImage};

let image_data = vec![0; 100 * 50 * 4];
let image = RgbaImage::from_raw(100, 50, image_data).unwrap();

let config = EncoderConfig::new(Codec::MozJpeg).with_quality(80.0).unwrap();
let file = File::create("output.jpg").expect("Failed to create file");

let encoder = Encoder::new(file, DynamicImage::ImageRgba8(image)).with_config(config);

encoder.encode()?;

Re-exports

Modules

  • Module for configuring image processing settings.
  • Module for library errors.

Structs

  • Decoder for reading and decoding images from various formats.
  • A struct for encoding images using various codecs.