Add image decoding support with image crate
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
//! Example: Download asset thumbnails
|
||||
|
||||
use image::GenericImageView;
|
||||
use immich_sdk::Client;
|
||||
use immich_sdk::models::AssetMediaSize;
|
||||
use std::fs;
|
||||
@@ -23,49 +24,27 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
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: {} bytes to {}",
|
||||
response.data().len(),
|
||||
output_path
|
||||
);
|
||||
println!("Saved thumbnail to {}", output_path);
|
||||
|
||||
// Download preview (medium size)
|
||||
let response = client
|
||||
.assets()
|
||||
.thumbnail(asset_id)
|
||||
.size(AssetMediaSize::Preview)
|
||||
.execute()
|
||||
.await?;
|
||||
// Decode the image
|
||||
println!("\nDecoding image...");
|
||||
let image = response.decode()?;
|
||||
println!("Image dimensions: {}x{}", image.width(), image.height());
|
||||
println!("Image color type: {:?}", image.color());
|
||||
|
||||
let ext = response.extension().unwrap_or("jpg");
|
||||
let output_path = format!("/path/to/output/preview.{}", ext);
|
||||
fs::write(&output_path, response.data())?;
|
||||
println!(
|
||||
"Saved preview: {} bytes to {}",
|
||||
response.data().len(),
|
||||
output_path
|
||||
);
|
||||
// Example: Get a specific pixel
|
||||
let pixel = image.get_pixel(0, 0);
|
||||
println!("Top-left pixel: {:?}", pixel);
|
||||
|
||||
// Download fullsize
|
||||
let response = client
|
||||
.assets()
|
||||
.thumbnail(asset_id)
|
||||
.size(AssetMediaSize::Fullsize)
|
||||
.execute()
|
||||
.await?;
|
||||
|
||||
let ext = response.extension().unwrap_or("jpg");
|
||||
let output_path = format!("/path/to/output/fullsize.{}", ext);
|
||||
fs::write(&output_path, response.data())?;
|
||||
println!(
|
||||
"Saved fullsize: {} bytes to {}",
|
||||
response.data().len(),
|
||||
output_path
|
||||
);
|
||||
// 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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user