Sample program to print Exif data from an image.
#include <exiv2/exiv2.hpp>
#include <iostream>
#include <regex>
while (pList->
tag_ != 0xffff && pList->
tag_ != tag)
pList++;
return pList->
tag_ != 0xffff ? pList :
nullptr;
}
int main(int argc, char* const argv[]) {
try {
setlocale(LC_CTYPE, ".utf8");
#ifdef EXV_ENABLE_BMFF
Exiv2::enableBMFF();
#endif
const char* prog = argv[0];
if (argc == 1) {
std::cout << "Usage: " << prog << " [ [--lint] path | --version | --version-test ]" << std::endl;
return EXIT_FAILURE;
}
int rc = EXIT_SUCCESS;
const char* file = argv[1];
bool bLint = strcmp(file, "--lint") == 0 && argc == 3;
if (bLint)
file = argv[2];
if (strcmp(file, "--version") == 0) {
std::vector<std::regex> keys;
return rc;
}
if (strcmp(file, "--version-test") == 0) {
std::cout << "EXV_PACKAGE_VERSION " << EXV_PACKAGE_VERSION << std::endl
<<
"strlen(Exiv2::version()) " << ::strlen(
Exiv2::version()) << std::endl
#if EXIV2_TEST_VERSION(0, 15, 0)
std::cout << "Available Exiv2 version is equal to or greater than 0.13\n";
} else {
std::cout << "Installed Exiv2 version is less than 0.13\n";
}
#else
std::cout << "Compile-time Exiv2 version doesn't have Exiv2::testVersion()\n";
#endif
return rc;
}
image->readMetadata();
std::string error("No Exif data found in file");
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
std::set<std::string> shortLong;
shortLong.insert("Exif.Photo.PixelXDimension");
shortLong.insert("Exif.Photo.PixelYDimension");
shortLong.insert("Exif.Photo.ImageLength");
shortLong.insert("Exif.Photo.ImageWidth");
shortLong.insert("Exif.Photo.RowsPerStrip");
shortLong.insert("Exif.Photo.StripOffsets");
shortLong.insert("Exif.Photo.StripByteCounts");
auto end = exifData.
end();
for (
auto i = exifData.
begin(); i != end; ++i) {
if (!bLint) {
const char* tn = i->typeName();
std::cout << std::setw(44) << std::setfill(' ') << std::left << i->key() << " "
<< "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i->tag() << " "
<< std::setw(9) << std::setfill(' ') << std::left << (tn ? tn : "Unknown") << " " << std::dec
<< std::setw(3) << std::setfill(' ') << std::right << i->count() << " " << std::dec << i->toString()
<< "\n";
} else {
if (tagInfo) {
&& (shortLong.find(i->key()) == shortLong.end() ||
) {
std::cerr << i->key() << " type " << i->typeName() << " (" << type << ")"
<< std::endl;
rc = 2;
}
}
}
}
return rc;
std::cout <<
"Caught Exiv2 exception '" << e.
what() <<
"'\n";
return EXIT_FAILURE;
}
}