You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.8 KiB
C++
58 lines
1.8 KiB
C++
// ***************************************************************** -*- C++ -*-
|
|
// iptceasy.cpp, $Rev$
|
|
// The quickest way to access, set or modify Iptc metadata.
|
|
|
|
#include "iptc.hpp"
|
|
#include "image.hpp"
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
|
|
int main(int argc, char* const argv[])
|
|
try {
|
|
if (argc != 2) {
|
|
std::cout << "Usage: " << argv[0] << " file\n";
|
|
return 1;
|
|
}
|
|
std::string file(argv[1]);
|
|
|
|
Exiv2::IptcData iptcData;
|
|
|
|
iptcData["Iptc.Application2.Headline"] = "The headline I am";
|
|
iptcData["Iptc.Application2.Keywords"] = "Yet another keyword";
|
|
iptcData["Iptc.Application2.DateCreated"] = "2004-8-3";
|
|
iptcData["Iptc.Application2.Urgency"] = uint16_t(1);
|
|
iptcData["Iptc.Envelope.ModelVersion"] = 42;
|
|
iptcData["Iptc.Envelope.TimeSent"] = "14:41:0-05:00";
|
|
iptcData["Iptc.Application2.RasterizedCaption"] = "230 42 34 2 90 84 23 146";
|
|
iptcData["Iptc.0x0009.0x0001"] = "Who am I?";
|
|
|
|
Exiv2::StringValue value;
|
|
value.read("very!");
|
|
iptcData["Iptc.Application2.Urgency"] = value;
|
|
|
|
std::cout << "Time sent: " << iptcData["Iptc.Envelope.TimeSent"] << "\n";
|
|
|
|
// Open image file
|
|
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
|
|
if (image.get() == 0) {
|
|
std::string error(file);
|
|
error += " : Could not read file or unknown image type";
|
|
throw Exiv2::Error(error);
|
|
}
|
|
|
|
// Read existing metdata (so that exif will be preserved)
|
|
int rc = image->readMetadata();
|
|
if (rc) {
|
|
std::string error = Exiv2::Image::strError(rc, file);
|
|
throw Exiv2::Error(error);
|
|
}
|
|
|
|
// Replace Iptc data and write it back to the file
|
|
image->setIptcData(iptcData);
|
|
return image->writeMetadata();
|
|
}
|
|
catch (Exiv2::Error& e) {
|
|
std::cout << "Caught Exiv2 exception '" << e << "'\n";
|
|
return -1;
|
|
}
|