Skip to content
smallPict
Start free
HomeIntegrationsRust crate

Async image optimization client for Rust

Integrate SmallPict inside high-throughput backend services written in Actix-Web, Axum, or Tokio. Process and upload media buffers with maximum memory efficiency.

Install

RUST Package
$ cargo add smallpict-rs

Implementation example

rust
use smallpict_rs::{SmallPictClient, OptimizeOptions, ImageFormat};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = SmallPictClient::new("sp_live_secret_key_xxxxx")?;
    
    let image_bytes = tokio::fs::read("input.jpg").await?;
    let optimized = client.optimize(&image_bytes, OptimizeOptions {
        format: ImageFormat::Avif,
        quality: 80,
        max_width: Some(1920),
        strip_metadata: true,
    }).await?;
    
    tokio::fs::write("output.avif", optimized.bytes).await?;
    println!("Savings: {}% ({}ms)", optimized.savings_percentage, optimized.duration_ms);
    Ok(())
}

Integration steps

  1. Add dependency

    Add smallpict-rs to your Cargo.toml file.

  2. Initialize client

    Create a SmallPictClient with your API key or an environment variable.

  3. Optimize byte stream

    Stream raw image bytes and receive compressed AVIF/WebP buffers asynchronously.

Key benefits

  • Async non-blocking I/O powered by Tokio & Reqwest
  • Thread-safe client
  • Direct stream buffer processing without local disk writes
  • Small, fast client

Need complete implementation guides & API specs?

Explore parameter references, authentication mechanisms, error codes, and local testing instructions in our official Rust crate developer guide.

Read Rust crate Docs

Speed Up Your Rust crate Image Pipeline

Try AVIF and WebP image optimization in your application. No setup fee, and sandbox keys right away.