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
$ cargo add smallpict-rsImplementation example
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
Add dependency
Add smallpict-rs to your Cargo.toml file.
Initialize client
Create a SmallPictClient with your API key or an environment variable.
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 DocsSpeed Up Your Rust crate Image Pipeline
Try AVIF and WebP image optimization in your application. No setup fee, and sandbox keys right away.