//! Example: Download asset thumbnails //! //! This example uses environment variables for configuration: //! - IMMICH_URL: The Immich server URL (defaults to http://localhost:2283) //! - IMMICH_API_KEY: Your API key (required) use image::GenericImageView; use immich_sdk::Client; use immich_sdk::models::AssetMediaSize; use std::fs; #[tokio::main] async fn main() -> Result<(), Box> { // Configure the client from environment variables let url = std::env::var("IMMICH_URL").unwrap_or_else(|_| "http://localhost:2283".to_string()); let api_key = std::env::var("IMMICH_API_KEY").expect("IMMICH_API_KEY environment variable not set"); // Create a client let client = Client::from_url(&url)?.with_api_key(api_key); // Get first asset from the server let assets = client.assets().list().execute().await?; if assets.is_empty() { println!("No assets found. Run upload_photos example first."); return Ok(()); } let asset_id = assets[0].id; // 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(()) }