Using the Exiv2 library to write some exif tags to an image i'm running the below code, similar to the examples provided on the Exiv2 site.
However, some throw errors and some simply don't write but throw no errors. I've noticed that tags with Exif.Image.* don't work and some with Exif.Photo.* work and some don't, but can't find a pattern.
I'm checking what's written to the file by using JHEAD.
Wondering if anyone has come across this behaviour in the past or knows whats going on? Thanks.
Exiv2::ExifData exifData;
try {
// these work fine
exifData["Exif.Photo.FNumber"] = Exiv2::Rational(7, 5);
exifData["Exif.Photo.ExposureTime"] = Exiv2::Rational(1, 1);
exifData["Exif.Photo.WhiteBalance"] = uint16_t(1);
exifData["Exif.Photo.ShutterSpeedValue"] = Exiv2::Rational(1, 1);
exifData["Exif.Photo.DateTimeOriginal"] = "12:12:12";
// throw errors
exifData["Exif.Photo.ISOSpeed"] = int32_t(2);
// don't throw error, but don't write to jpg
exifData["Exif.Photo.GainControl"] = uint16_t(0);
exifData["Exif.Photo.Saturation"] = uint16_t(100);
exifData["Exif.Photo.Sharpness"] = uint16_t(2);
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open("filepath");
assert(image.get() != 0);
image->setExifData(exifData);
image->writeMetadata();
}
catch (Exiv2::AnyError& e) {
cout << "Caught Exiv2 exception '" << e << "'\n";
}
Running this code with both a JPEG and a TIFF image, I can't reproduce the problems described; it doesn't throw any exception and all tags are written to the image.
It is however true that Exiv2 silently does not write certain tags. That happens if the target image is a TIFF-like image, it does not happen with JPEGs. The tags that are ignored are TIFF "image tags" that Exiv2 considers relevant for the integrity of the image itself, since in the structure of TIFF-like images, image tags and metadata co-exist. All of these image tags are from the "Image" group (Exif.Image.*), an example is Exif.Image.ImageWidth.
If you can provide a reproducer - or a target image in addition to the above code - that triggers the described behavior, please report this as an issue in the Exiv2 bugtracker at dev.exiv2.org.
Andreas