diff options
Diffstat (limited to 'lib/exif_wrapper.cpp')
-rw-r--r-- | lib/exif_wrapper.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/exif_wrapper.cpp b/lib/exif_wrapper.cpp index eab5598..21ee6c6 100644 --- a/lib/exif_wrapper.cpp +++ b/lib/exif_wrapper.cpp @@ -35,10 +35,38 @@ extern "C" unsigned int getExifOrientation(uint8_t* imgBytes, unsigned int size) } } + +extern "C" void setExifOrientation(char* fileName, unsigned int orientation) { + try { + // Exiv init + Exiv2::XmpParser::initialize(); + ::atexit(Exiv2::XmpParser::terminate); + Exiv2::enableBMFF(); + + // using blob works, except that exiv2 won't write back to the blob :( + // std::unique_ptr<Exiv2::Image> image = Exiv2::ImageFactory::open(imgBytes, size); + // So instead we load from the temp file + std::unique_ptr<Exiv2::Image> image = Exiv2::ImageFactory::open(fileName); + assert(image.get() != 0); + image->readMetadata(); + Exiv2::ExifData &exifData = image->exifData(); + + exifData[ORIENTATION_KEY] = orientation; + + // Save exif to image object & save image back to file + image->setExifData(exifData); + image->writeMetadata(); + } + catch (Exiv2::Error& e) { + std::cout << "Caught Exiv2 exception '" << e.what() << "'\n"; + } +} +/* extern "C" void setExifOrientation(uint8_t* imgBytes, unsigned int size, unsigned int orientation) { try { // Hack to work around Exiv2 seeming to refuse to write back to blob, but will write // back to a file. Create temp file -> operate on it -> copy back to blob, unlink file. + // tmpFileName gets overwritten with the actual filename by mkstemp char tmpFileName[] = "/tmp/image-temp.XXXXXX"; int fd = mkstemp(tmpFileName); assert(fd != -1); @@ -74,4 +102,4 @@ extern "C" void setExifOrientation(uint8_t* imgBytes, unsigned int size, unsigne catch (Exiv2::Error& e) { std::cout << "Caught Exiv2 exception '" << e.what() << "'\n"; } -} +}*/ |