Files
immich-sdk/examples/thumbnail.rs
2026-04-06 08:30:37 +00:00

51 lines
1.6 KiB
Rust

//! Example: Download asset thumbnails
use image::GenericImageView;
use immich_sdk::Client;
use immich_sdk::models::AssetMediaSize;
use std::fs;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a client
let client = Client::from_url("https://immich.example.com")?.with_api_key("your-api-key");
// Asset ID to download thumbnail for
let asset_id = "your-asset-id-here".parse()?;
// Download thumbnail (small size, default)
println!("Downloading thumbnail...");
let response = client
.assets()
.thumbnail(asset_id)
.size(AssetMediaSize::Thumbnail)
.execute()
.await?;
println!("Content type: {}", response.content_type());
println!("Extension: {:?}", response.extension());
println!("Data size: {} bytes", response.data().len());
// Save raw bytes
let ext = response.extension().unwrap_or("jpg");
let output_path = format!("/path/to/output/thumbnail.{}", ext);
fs::write(&output_path, response.data())?;
println!("Saved thumbnail to {}", output_path);
// Decode the image
println!("\nDecoding image...");
let image = response.decode()?;
println!("Image dimensions: {}x{}", image.width(), image.height());
println!("Image color type: {:?}", image.color());
// Example: Get a specific pixel
let pixel = image.get_pixel(0, 0);
println!("Top-left pixel: {:?}", pixel);
// Example: Resize image (requires image crate features)
// let resized = image.resize(100, 100, image::imageops::FilterType::Lanczos3);
// println!("Resized to: {}x{}", resized.width(), resized.height());
Ok(())
}