-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_thumbnail.rs
More file actions
47 lines (39 loc) · 1.56 KB
/
Copy pathextract_thumbnail.rs
File metadata and controls
47 lines (39 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! Example demonstrating thumbnail extraction from 3MF files
//!
//! This example shows how to:
//! - Check if a 3MF file contains a thumbnail
//! - Extract thumbnail metadata (path and content type)
//! - Read the thumbnail binary data and save it to a file
use lib3mf::Model;
use std::fs::File;
use std::io::Write;
const TEST_FILE: &str = "test_files/test_thumbnail.3mf";
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Parse a 3MF file
let file = File::open(TEST_FILE)?;
let model = Model::from_reader(file)?;
// Check if model has a thumbnail
if let Some(ref thumbnail) = model.thumbnail {
println!("Thumbnail found!");
println!(" Path: {}", thumbnail.path);
println!(" Content Type: {}", thumbnail.content_type);
// Read the thumbnail binary data
let file = File::open(TEST_FILE)?;
if let Some(thumbnail_data) = Model::read_thumbnail(file)? {
println!(" Size: {} bytes", thumbnail_data.len());
// Save thumbnail to a file
let output_path = "extracted_thumbnail.png";
let mut output_file = File::create(output_path)?;
output_file.write_all(&thumbnail_data)?;
println!(" Saved to: {}", output_path);
}
} else {
println!("No thumbnail found in this 3MF file");
}
// Display basic model info
println!("\nModel Information:");
println!(" Unit: {}", model.unit);
println!(" Objects: {}", model.resources.objects.len());
println!(" Build items: {}", model.build.items.len());
Ok(())
}