iptceasy.cpp

The quickest way to access, set or modify IPTC metadata

00001 // ***************************************************************** -*- C++ -*-
00002 // iptceasy.cpp, $Rev: 560 $
00003 // The quickest way to access, set or modify Iptc metadata.
00004 
00005 #include "iptc.hpp"
00006 #include "image.hpp"
00007 #include <iostream>
00008 #include <iomanip>
00009 #include <cassert>
00010 
00011 int main(int argc, char* const argv[])
00012 try {
00013     if (argc != 2) {
00014         std::cout << "Usage: " << argv[0] << " file\n";
00015         return 1;
00016     }
00017     std::string file(argv[1]);
00018 
00019     Exiv2::IptcData iptcData;
00020 
00021     iptcData["Iptc.Application2.Headline"] = "The headline I am";
00022     iptcData["Iptc.Application2.Keywords"] = "Yet another keyword";
00023     iptcData["Iptc.Application2.DateCreated"] = "2004-8-3";
00024     iptcData["Iptc.Application2.Urgency"] = uint16_t(1);
00025     iptcData["Iptc.Envelope.ModelVersion"] = 42;
00026     iptcData["Iptc.Envelope.TimeSent"] = "14:41:0-05:00";
00027     iptcData["Iptc.Application2.RasterizedCaption"] = "230 42 34 2 90 84 23 146";
00028     iptcData["Iptc.0x0009.0x0001"] = "Who am I?";
00029 
00030     Exiv2::StringValue value;
00031     value.read("very!");
00032     iptcData["Iptc.Application2.Urgency"] = value;
00033 
00034     std::cout << "Time sent: " << iptcData["Iptc.Envelope.TimeSent"] << "\n";
00035 
00036     // Open image file
00037     Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
00038     assert (image.get() != 0);
00039 
00040     // Set Iptc data and write it to the file
00041     image->setIptcData(iptcData);
00042     image->writeMetadata();
00043 
00044     return 0;
00045 }
00046 catch (Exiv2::AnyError& e) {
00047     std::cout << "Caught Exiv2 exception '" << e << "'\n";
00048     return -1;
00049 }

Generated on Thu Oct 4 09:44:18 2007 for Exiv2 by  doxygen 1.5.3