Lua
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local xmp = chilkat.Xmp.new()
-- Load a JPG or TIF image file.
local success = xmp:load_app_file("qa_data/xmp/AJ_123642_1511.tif")
if not success then
print(xmp.last_error_text)
return
end
print("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 then
print("No XMP metadata already exists..")
return
end
-- Get the XMP metadata.
local xml = xmp:get_embedded(0)
-- Show the XML:
print(xml:get_xml())
-- Update (overwrite) a string property.
xmp:add_simple_str(xml, "NumberofTimes", "123")
success = xmp:save_app_file("qa_output/updated.tif")
if not success then
print(xmp.last_error_text)
return
end
print("Success.")