- Main Page
- Namespaces
- Classes
- Files
- Examples

# iptcprint.cpp

Sample program to print the Iptc metadata of an image

    00001 // ***************************************************************** -*- C++ -*-
    00002 // iptcprint.cpp, $Rev: 631 $
    00003 // Sample program to print the Iptc metadata of an image
    00004
    00005 #include "image.hpp"
    00006 #include "iptc.hpp"
    00007 #include <iostream>
    00008 #include <iomanip>
    00009 #include <cassert>
    00010
    00011 int main(int argc, char* const argv[])
    00012 try {
    00013
    00014     if (argc != 2) {
    00015         std::cout << "Usage: " << argv[0] << " file\n";
    00016         return 1;
    00017     }
    00018
    00019     Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]);
    00020     assert (image.get() != 0);
    00021     image->readMetadata();
    00022
    00023     Exiv2::IptcData &iptcData = image->iptcData();
    00024     if (iptcData.empty()) {
    00025         std::string error(argv[1]);
    00026         error += ": No Iptc data found in the file";
    00027         throw Exiv2::Error(1, error);
    00028     }
    00029
    00030     Exiv2::IptcData::iterator end = iptcData.end();
    00031     for (Exiv2::IptcData::iterator md = iptcData.begin(); md != end; ++md) {
    00032         std::cout << std::setw(44) << std::setfill(' ') << std::left
    00033                   << md->key() << " "
    00034                   << "0x" << std::setw(4) << std::setfill('0') << std::right
    00035                   << std::hex << md->tag() << " "
    00036                   << std::setw(9) << std::setfill(' ') << std::left
    00037                   << md->typeName() << " "
    00038                   << std::dec << std::setw(3)
    00039                   << std::setfill(' ') << std::right
    00040                   << md->count() << "  "
    00041                   << std::dec << md->value()
    00042                   << std::endl;
    00043     }
    00044
    00045     return 0;
    00046 }
    00047 catch (Exiv2::AnyError& e) {
    00048     std::cout << "Caught Exiv2 exception '" << e << "'\n";
    00049     return -1;
    00050 }