1 unstable release
| 0.1.0 | Jan 27, 2026 |
|---|
#283 in Images
16KB
264 lines
GLM Image Metadata Extractor - Rust Implementation
This Rust implementation was inspired by glmimage.app. It provides efficient extraction and analysis of metadata from AI-generated images, including model signatures, generation parameters, and provenance tracking.
Features
- PNG Chunk Parsing: Pure Rust implementation for reading PNG chunks
- EXIF Metadata Extraction: Extract standard EXIF data from images
- AI Signature Validation: Verify and validate AI model signatures
- Provenance Tracking: Track the origin and generation parameters of AI images
- Memory Safety: Rust's ownership model ensures memory safety
- Zero-Copy Parsing: Efficient parsing with minimal allocations
Installation
cd rust
cargo build --release
Usage
Basic Usage
use glmimage_app_oss::{extract_ai_metadata, print_metadata_summary};
fn main() {
match extract_ai_metadata("generated-image.png") {
Ok(metadata) => print_metadata_summary(&metadata),
Err(e) => eprintln!("Error: {}", e),
}
}
Creating Metadata Programmatically
use glmimage_app_oss::{AIMetadata, validate_ai_signature};
fn main() {
let mut metadata = AIMetadata::new()
.with_model("GLM-4V-Image")
.with_prompt("A beautiful sunset over mountains")
.with_dimensions(1024, 1024);
let is_valid = validate_ai_signature(&mut metadata);
println!("Valid: {}", is_valid);
}
Running the Demo
cargo run --release
API Reference
extract_ai_metadata(image_path: &str) -> Result<AIMetadata, String>
Extracts AI metadata from an image file. Returns a Result containing AIMetadata or an error message.
validate_ai_signature(metadata: &mut AIMetadata) -> bool
Validates the AI model signature in the metadata. Returns true if valid.
embed_provenance_metadata(metadata: &mut AIMetadata, source: &str)
Adds provenance information to the metadata object.
print_metadata_summary(metadata: &AIMetadata)
Prints a formatted summary of the extracted metadata to the console.
Data Structures
pub struct AIMetadata {
pub model: String,
pub prompt: String,
pub parameters: HashMap<String, String>,
pub timestamp: String,
pub provenance: String,
pub signature: String,
pub width: u32,
pub height: u32,
pub format: String,
}
Builder Pattern
The AIMetadata struct provides builder methods:
.with_model(&str)- Set the model name.with_prompt(&str)- Set the prompt.with_dimensions(u32, u32)- Set width and height
Testing
cargo test
Linting
cargo clippy
Formatting
cargo fmt
Links
- Source: glmimage.app
- Repository: https://github.com/user/glmimage-app-oss
- Crates.io: https://crates.io/crates/glmimage-app-oss
License
MIT License - see LICENSE for details.