Files
immich-sdk/examples/thumbnail.rs
Joakim Hulthe 2e7db3b35a Add integration testing infrastructure with Podman Compose
- Add docker/podman-compose.yml for Immich server (no ML)
- Add test-data/sample-photos/ with 3 public domain images
- Add scripts/start-immich.sh for container startup + admin/API key creation
- Add scripts/seed-data.sh for uploading test photos and creating albums
- Add scripts/stop-immich.sh for cleanup with volume destruction
- Add scripts/run-example.sh wrapper (fixed env var export)
- Update examples to use IMMICH_URL and IMMICH_API_KEY env vars
- Add .github/workflows/integration-test.yml for CI
- Update assets.list() to use /search/metadata endpoint
- Update AGENTS.md with example running instructions
- Add 5 new examples: search_metadata, album_management, timeline_browsing,
  delete_assets, server_info
2026-04-14 20:13:30 +00:00

65 lines
2.2 KiB
Rust

//! 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<dyn std::error::Error>> {
// 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(())
}