Blame samples/exifvalue.cpp

Packit Service 21b5d1
// ***************************************************************** -*- C++ -*-
Packit Service 21b5d1
// exifvalue.cpp
Packit Service 21b5d1
// Sample program to print value of an exif key in an image
Packit Service 21b5d1
Packit Service 21b5d1
#include <exiv2/exiv2.hpp>
Packit Service 21b5d1
Packit Service 21b5d1
#include <iostream>
Packit Service 21b5d1
#include <iomanip>
Packit Service 21b5d1
#include <cassert>
Packit Service 21b5d1
#include <string>
Packit Service 21b5d1
Packit Service 21b5d1
int main(int argc, char* const argv[])
Packit Service 21b5d1
{
Packit Service 21b5d1
    if (argc != 3) {
Packit Service 21b5d1
        std::cerr << "Usage: " << argv[0] << " file key\n";
Packit Service 21b5d1
        return 1;
Packit Service 21b5d1
    }
Packit Service 21b5d1
Packit Service 21b5d1
    const char* file = argv[1];
Packit Service 21b5d1
    const char* key  = argv[2];
Packit Service 21b5d1
Packit Service 21b5d1
    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
Packit Service 21b5d1
    assert(image.get() != 0);
Packit Service 21b5d1
    image->readMetadata();
Packit Service 21b5d1
    Exiv2::ExifData &exifData = image->exifData();
Packit Service 21b5d1
Packit Service 21b5d1
    if ( exifData.empty()) {
Packit Service 21b5d1
		std::cerr << "no metadata found in file " << file << std::endl;
Packit Service 21b5d1
		exit(2);
Packit Service 21b5d1
	}
Packit Service 21b5d1
Packit Service 21b5d1
	try {
Packit Service 21b5d1
     	std::cout << exifData[key] << std::endl;
Packit Service 21b5d1
	} catch (Exiv2::AnyError& e) {
Packit Service 21b5d1
    	std::cerr << "Caught Exiv2 exception '" << e << "'" << std::endl;
Packit Service 21b5d1
    	exit(3);
Packit Service 21b5d1
	} catch ( ... ) {
Packit Service 21b5d1
		std::cerr << "Caught a cold!" << std::endl;
Packit Service 21b5d1
    	exit(4);
Packit Service 21b5d1
	}
Packit Service 21b5d1
Packit Service 21b5d1
    return 0;
Packit Service 21b5d1
}