Search code examples
c++exiv2

Exiv2 won't persist XMP to an image. image->writeMetaData() writes no metadata. Where is my error?


when I try to add XMP metadata to a file using exiv2 as library it just won't stick. After executing my code the file was modified, but has not changed in size and contains no XMP metadata. The following code is my testcase.

string fileName = "test.png";
vector<string> keyWords;
keyWords.push_back("keyword 1");
keyWords.push_back("keyword 2");
Exiv2::XmpParser::initialize();
image = Exiv2::ImageFactory::open(fileName);
assert(image.get() != 0);
assert(image->good());
image->readMetadata();
Exiv2::XmpData& xmpData = image->xmpData();
Exiv2::Value::AutoPtr subjects = Exiv2::Value::create(Exiv2::xmpBag);
for each (auto kw in keyWords)
    subjects->read(kw);
xmpData.add(Exiv2::XmpKey("Xmp.dc.subject"), subjects.get());
image->writeMetadata();

I tried the same using the precompiled command line tool which works.

exiv2 -v -k -m addxmp.txt mo test.png
File 1/1: test.png
Add Xmp.dc.subject "keyword1" (XmpBag)

I dug through the original source but found no difference. What is it that I do not see?

I'm running VS2019 on Windows 10 and this is a Cmake project which manages it's dependencies with vcpkg. exiv2 is installed via vcpkg.


Solution

  • If you use exiv2 libaries with vcpkg and need XMP support make sure to install it like this not forgetting the xmp in brackets...

    vcpkg install exiv2[xmp]:x64-windows