Add thumbnail endpoint with size options
This commit is contained in:
50
examples/thumbnail.rs
Normal file
50
examples/thumbnail.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
//! Example: Download asset thumbnails
|
||||
|
||||
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 thumbnail = client
|
||||
.assets()
|
||||
.thumbnail(asset_id)
|
||||
.size(AssetMediaSize::Thumbnail)
|
||||
.execute()
|
||||
.await?;
|
||||
|
||||
fs::write("/path/to/output/thumbnail.jpg", &thumbnail)?;
|
||||
println!("Saved thumbnail: {} bytes", thumbnail.len());
|
||||
|
||||
// Download preview (medium size)
|
||||
let preview = client
|
||||
.assets()
|
||||
.thumbnail(asset_id)
|
||||
.size(AssetMediaSize::Preview)
|
||||
.execute()
|
||||
.await?;
|
||||
|
||||
fs::write("/path/to/output/preview.jpg", &preview)?;
|
||||
println!("Saved preview: {} bytes", preview.len());
|
||||
|
||||
// Download fullsize
|
||||
let fullsize = client
|
||||
.assets()
|
||||
.thumbnail(asset_id)
|
||||
.size(AssetMediaSize::Fullsize)
|
||||
.execute()
|
||||
.await?;
|
||||
|
||||
fs::write("/path/to/output/fullsize.jpg", &fullsize)?;
|
||||
println!("Saved fullsize: {} bytes", fullsize.len());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user