Sample code for 30+ languages & platforms
Rust

Update a String Property in XMP

See more XMP Examples

Demonstrates how to open a JPG or TIF image file, access the XMP metadata, and update the value of a string property. (If the string property does not already exist, it is created.)

Chilkat Rust Downloads

Rust

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let xmp = chilkat::Xmp::new();

// Load a JPG or TIF image file.
if xmp.load_app_file("qa_data/xmp/AJ_123642_1511.tif").is_err() {
    println!("{}", xmp.last_error_text());
    return;
}

println!("Num embedded XMP docs: {}", xmp.num_embedded());

// This example assumes that XMP metadata is already present in the image file.
if xmp.num_embedded() == 0 {
    println!("No XMP metadata already exists..");
    return;
}

// Get the XMP metadata.
let xml = xmp.get_embedded(0).unwrap();

// Show the XML:
println!("{}", xml.get_xml().unwrap_or_default());

// Update (overwrite) a string property.
let _ = xmp.add_simple_str(&xml, "NumberofTimes", "123");

if xmp.save_app_file("qa_output/updated.tif").is_err() {
    println!("{}", xmp.last_error_text());
    return;
}

println!("Success.");