Skip to content

Instantly share code, notes, and snippets.

@sorin-davidoi
Last active August 29, 2015 14:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sorin-davidoi/c19b8e7e70d253568d6a to your computer and use it in GitHub Desktop.
CyanogenMod DateTime Exif fix for "1970:01:01 02:00:00"
/**
* This is a fix for a bug in CyanogenMod (I think) that causes the DateTime Exif tag
* in photos taken with the camera to be set to "1970:01:01 02:00:00" while the corect
* date is stored in DateTimeOriginal. This causes problems for photo manipulation programs
* like Digikam.
*
* The fix consists in overriding the DateTime tag with the content of DateTimeOriginal if
* the DateTime tag is equal to "1970:01:01 02:00:00".
*
* Compile with: g++ -o cyanogenmod-exif-fix cyanogenmod-exif-fix.cpp -l exiv2
*
* The exiv2 library is required in order to compile and run the program. Most likely
* it is in your distribution repositories.
*
* The files to be 'fixed' are to be provided via command line arguments.
*
* Please note the fix will happen in-place, so make a backup first.
*/
#include <iostream>
#include <exiv2/exiv2.hpp>
using namespace std;
using namespace Exiv2;
int main(int argc, char ** argv) {
std::string wrongDate("1970:01:01 02:00:00");
ExifKey dateTimeOriginalKey("Exif.Image.DateTimeOriginal");
ExifKey dateTimeKey("Exif.Image.DateTime");
for(int i = 1; i < argc; ++i) {
Image::AutoPtr image = ImageFactory::open(argv[i]);
image->readMetadata();
ExifData & exif = image->exifData();
ExifData::iterator it = exif.findKey(dateTimeKey);
// If the image contains the DateTime tag and it is incorrect
if(it != exif.end() && it->toString() == wrongDate) {
ExifData::iterator sit = exif.findKey(dateTimeOriginalKey);
// If the image contains the DateTimeOriginal tag
if(sit != exif.end()) {
// Override DateTime with DateTimeOriginal
(* it) = sit->toString();
image->writeMetadata();
cout << "Fixed: " << argv[i] << "\n";
} else {
cout << "Not fixed: " << argv[i] << "\n";
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment