Scheme for adding a valid license to an image using Adobe XMP Toolkit

In continuation of my previous post, I’ve created a sample which stores the licenses, uses the XMP Toolkit to create the valid XMP packet, and applies it to a file. The real take-away is the library function which allows easy creation of XMP packets and can be used now in C++ programs. However, the size of the XMP toolkit is large as it will still take whittling away the dense and irrelevant code, or integrate it into wrappers like the Android XMP kit that my fellow team members are working on. The following code is adapted from code released by my colleague Gideon Thomas.

I am using an XMP metadata packet instance and enums in for the function parameters. Using enums allows coders to easily reference a CC license without the use of “magic numbers”. These enums are used to access a map which contains instances of license objects, which in turn contain the license information.

AddLicense(MyXMPPacket, CC_ATTRIBUTION) is the function where MyXMPPacket is an XMP packet which is either new or contains a previous license and CC_ATTRIBUTION is the enum which could be any of 6 creative commons licenses.

In order to determine how to add the specific properties using the API, I referenced this list, as well as this.

Snippets from the code

Note: These are condensed, for proper usage reference the files.

The code which adds a license to correct properties is:
“URI” is where the license URI is placed as a string.
“Description” is where description for Usage Terms would be placed.
meta->SetProperty(kXMP_NS_XMP_Rights, "Marked", "True", 0);
meta->SetProperty(kXMP_NS_XMP_Rights, "WebStatement", "URI", 0);
meta->SetProperty(kXMP_NS_XMP_Rights, "UsageTerms", "Description", 0);

kXMP_NS_XMP references the namespace “” which is defined in XMP_Toolkit/public/include/XMP_Const.h (a great resource for those working with the XMP Toolkit for any reason).

To affix the code to the file:
myFile.OpenFile(filename, kXMP_UnknownFile, opts);

In this release is the new license class, library code in conjunction with the test code. In order to compile this, you will also need the aforementioned adobe XMP library repaired for OSX compilation by my colleague Gideon Thomas.

Screenshot 2015-02-20 17.28.37

1. C++ Files
2. Image with license added