Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set xmp [new_CkXmp]

# Load a JPG or TIF image file.
set success [CkXmp_LoadAppFile $xmp "qa_data/xmp/AJ_123642_1511.tif"]
if {$success != 1} then {
    puts [CkXmp_lastErrorText $xmp]
    delete_CkXmp $xmp
    exit
}

puts "Num embedded XMP docs: [CkXmp_get_NumEmbedded $xmp]"

# This example assumes that XMP metadata is already present in the image file.
if {[CkXmp_get_NumEmbedded $xmp] == 0} then {
    puts "No XMP metadata already exists.."
    delete_CkXmp $xmp
    exit
}

# Get the XMP metadata.
# xml is a CkXml

set xml [CkXmp_GetEmbedded $xmp 0]

# Show the XML:
puts [CkXml_getXml $xml]

# Update (overwrite) a string property.
CkXmp_AddSimpleStr $xmp $xml "NumberofTimes" "123"

set success [CkXmp_SaveAppFile $xmp "qa_output/updated.tif"]
if {$success != 1} then {
    puts [CkXmp_lastErrorText $xmp]
    delete_CkXmp $xmp
    exit
}

puts "Success."

delete_CkXmp $xmp