void ExifTransfer::copyEXIF() { static const char * includeImageKeys[] = { // Correct Make and Model, from the input files // It is needed so that makernote tags are correctly copied "Exif.Image.Make", "Exif.Image.Model", "Exif.Image.Artist", "Exif.Image.Copyright", "Exif.Image.DNGPrivateData", // Opcodes generated by Adobe DNG converter "Exif.SubImage1.OpcodeList1", "Exif.SubImage1.OpcodeList2", "Exif.SubImage1.OpcodeList3" }; const Exiv2::ExifData & srcExif = src->exifData(); Exiv2::ExifData & dstExif = dst->exifData(); for (const char * keyName : includeImageKeys) { auto iterator = srcExif.findKey(Exiv2::ExifKey(keyName)); if (iterator != srcExif.end()) { dstExif[keyName] = *iterator; } } // Now we set the SubImage1 file type to Primary Image // Exiv2 wouldn't modify SubImage1 tags if it was set before dstExif["Exif.SubImage1.NewSubfileType"] = 0; for (const auto & datum : srcExif) { if (!excludeExifDatum(datum) && dstExif.findKey(Exiv2::ExifKey(datum.key())) == dstExif.end()) { dstExif.add(datum); } } }
void ExifTransfer::copyMetadata() { try { dst = Exiv2::ImageFactory::open(BasicIo::AutoPtr(new MemIo(data, dataSize))); dst->readMetadata(); } catch (Exiv2::Error & e) { std::cerr << "Exiv2 error: " << e.what() << std::endl; return; } try { src = Exiv2::ImageFactory::open(srcFile.toLocal8Bit().constData()); src->readMetadata(); copyXMP(); copyIPTC(); copyEXIF(); } catch (Exiv2::Error & e) { std::cerr << "Exiv2 error: " << e.what() << std::endl; // At least we have to set the SubImage1 file type to Primary Image dst->exifData()["Exif.SubImage1.NewSubfileType"] = 0; } try { dst->writeMetadata(); FileIo fileIo(dstFile.toLocal8Bit().constData()); fileIo.open("wb"); fileIo.write(dst->io()); fileIo.close(); } catch (Exiv2::Error & e) { std::cerr << "Exiv2 error: " << e.what() << std::endl; } }
void write(const std::string& file, Exiv2::ExifData& ed) { Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file); assert (image.get() != 0); image->setExifData(ed); image->writeMetadata(); }
int main(int argc, char* const argv[]) try { if (argc != 2) { std::cout << "Usage: " << argv[0] << " file\n"; return 1; } Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]); assert(image.get() != 0); image->readMetadata(); const std::string& xmpPacket = image->xmpPacket(); if (xmpPacket.empty()) { std::string error(argv[1]); error += ": No XMP packet found in the file"; throw Exiv2::Error(1, error); } std::cout << xmpPacket << "\n"; return 0; } catch (Exiv2::AnyError& e) { std::cout << "Caught Exiv2 exception '" << e << "'\n"; return -1; }
int populateMetaExif(std::string file, std::string plate) { try { Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file); std::string comment = plate + ' '+ "LOT50"; //Add code to get information about lot if(!image.get()) { throw Exiv2::Error(1, "Failed to open image"); } image->readMetadata(); Exiv2::ExifData &exifData = image->exifData(); exifData["Exif.Photo.UserComment"]= comment; //std::cout<< "Writing Exiv User Comment "<< exifData["Exif.Image.ImageDescription"] <<"\n"; image->writeMetadata(); } catch (Exiv2::AnyError& e) { std::cout << "Problem Writing Metadata '" << e << "'\n"; return -1; } return 0; }
void print(const std::string& file) { Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file); assert(image.get() != 0); image->readMetadata(); Exiv2::ExifData &ed = image->exifData(); Exiv2::ExifData::const_iterator end = ed.end(); for (Exiv2::ExifData::const_iterator i = ed.begin(); i != end; ++i) { std::cout << std::setw(45) << std::setfill(' ') << std::left << i->key() << " " << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i->tag() << " " << std::setw(12) << std::setfill(' ') << std::left << i->ifdName() << " " << std::setw(9) << std::setfill(' ') << std::left << i->typeName() << " " << std::dec << std::setw(3) << std::setfill(' ') << std::right << i->count() << " " << std::dec << i->value() << "\n"; } }
Exiv2::ExifData getExifFromPath(char* filename) { qDebug() << "Trying to read EXIF for" << filename; try { Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename); assert(image.get() != 0); image->readMetadata(); Exiv2::ExifData &exifData = image->exifData(); if (exifData.empty()) { std::string error(filename); error += ": No Exif data found in the file"; //TODO Translate //throw Exiv2::Error(1, error); } return exifData; } catch (Exiv2::Error& e) { Exiv2::ExifData exifData; qCritical() << "Caught Exiv2 exception '" << e.what(); //TODO Translate return exifData; } }
/** \fn ImageUtils::GetExifValue(const QString &, const QString &, bool *) * \brief Reads and returns the value of an exif tag in a file * \param fileName The filename that holds the exif data * \param exifTag The key that shall be updated * \param ok Will be set to true if the reading was ok, otherwise false * \return The value of the exif tag or an empty string */ QString ImageUtils::GetExifValue(const QString &fileName, const QString &exifTag, bool *ok) { // Assume the exif reading fails *ok = false; // default value QString value(""); try { Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fileName.toLocal8Bit().constData()); if (image.get()) { image->readMetadata(); Exiv2::ExifData &exifData = image->exifData(); if (!exifData.empty()) { Exiv2::Exifdatum &datum = exifData[exifTag.toLocal8Bit().constData()]; value = QString::fromStdString(datum.toString()); if (!value.isEmpty()) { *ok = true; } else { LOG(VB_GENERAL, LOG_ERR, QString("Exiv2 error: No tag found, file %1, tag %2") .arg(fileName).arg(exifTag)); } } else { LOG(VB_GENERAL, LOG_ERR, QString("Exiv2 error: No header, file %1, tag %2") .arg(fileName).arg(exifTag)); } } else { LOG(VB_GENERAL, LOG_ERR, QString("Exiv2 error: Could not open file, file %1, tag %2") .arg(fileName).arg(exifTag)); } } catch (Exiv2::Error& e) { LOG(VB_GENERAL, LOG_ERR, QString("Exiv2 exception %1, file %2, tag %3") .arg(e.what()).arg(fileName).arg(exifTag)); } return value; }
void ExifTransfer::copyXMP() { const Exiv2::XmpData & srcXmp = src->xmpData(); Exiv2::XmpData & dstXmp = dst->xmpData(); for (const auto & datum : srcXmp) { if (datum.groupName() != "tiff" && dstXmp.findKey(Exiv2::XmpKey(datum.key())) == dstXmp.end()) { dstXmp.add(datum); } } }
bool imwrite_tiff(matrix<unsigned short> output, string outputfilename, Exiv2::ExifData exifData) { int xsize, ysize; xsize = output.nc()/3; ysize = output.nr(); outputfilename = outputfilename + ".tif"; TIFF *out = TIFFOpen(outputfilename.c_str(),"w"); if (!out) { cerr << "Can't open file for writing" << endl; return 1; } TIFFSetField(out, TIFFTAG_IMAGEWIDTH, xsize); TIFFSetField(out, TIFFTAG_IMAGELENGTH, ysize); TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 3); //RGB TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 16); TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); // set the origin of the image. //Magic below TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); //End Magic tsize_t linebytes = 3 * xsize * 2;//Size in bytes of a line unsigned short *buf = NULL; buf =(unsigned short *)_TIFFmalloc(linebytes); for (int j = 0; j < ysize; j++) { for(int i = 0; i < xsize; i ++) { buf[i*3 ] = output(j,i*3 ); buf[i*3+1] = output(j,i*3+1); buf[i*3+2] = output(j,i*3+2); } if (TIFFWriteScanline(out, buf, j, 0) < 0) break; } (void) TIFFClose(out); if (buf) _TIFFfree(buf); exifData["Exif.Image.Orientation"] = 1;//set all images to unrotated exifData["Exif.Image.ImageWidth"] = output.nr(); exifData["Exif.Image.ImageLength"] = output.nc()/3; Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(outputfilename.c_str()); assert(image.get() != 0); image->setExifData(exifData); //image->writeMetadata(); return 0; }
void ExifTransfer::copyIPTC() { const Exiv2::IptcData & srcIptc = src->iptcData(); Exiv2::IptcData & dstIptc = dst->iptcData(); for (const auto & datum : srcIptc) { if (dstIptc.findKey(Exiv2::IptcKey(datum.key())) == dstIptc.end()) { dstIptc.add(datum); } } }
bool JpegContent::loadFromData(const QByteArray& data) { Exiv2::Image::AutoPtr image; Exiv2ImageLoader loader; if (!loader.load(data)) { qCritical() << "Could not load image with Exiv2, reported error:" << loader.errorMessage(); } image = loader.popImage(); return loadFromData(data, image.get()); }
void RawParameters::loadCamXyzFromDng() { // Try to load it from the DNG metadata try { const float d65_white[3] = { 0.950456f, 1.0f, 1.088754f }; double cc[4][4], xyz[] = { 1,1,1 }; for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { cc[j][i] = i == j ? 1.0 : 0.0; } } Exiv2::Image::AutoPtr src = Exiv2::ImageFactory::open(fileName.toLocal8Bit().constData()); src->readMetadata(); const Exiv2::ExifData & srcExif = src->exifData(); auto ccData = srcExif.findKey(Exiv2::ExifKey("Exif.Image.CameraCalibration1")); if (ccData == srcExif.end()) { ccData = srcExif.findKey(Exiv2::ExifKey("Exif.Image.CameraCalibration2")); } if (ccData != srcExif.end()) { for (int i = 0; i < colors; ++i) { for (int j = 0; j < colors; ++j) { cc[i][j] = ccData->toFloat(i*colors + j); } } } auto xyzData = srcExif.findKey(Exiv2::ExifKey("Exif.Image.AsShotWhiteXY")); if (xyzData != srcExif.end()) { xyz[0] = xyzData->toFloat(0); xyz[1] = xyzData->toFloat(1); xyz[2] = 1.0 - xyz[0] - xyz[1]; for (int i = 0; i < 3; ++i) { xyz[i] /= d65_white[i]; } } auto cmData = srcExif.findKey(Exiv2::ExifKey("Exif.Image.ColorMatrix1")); if (cmData == srcExif.end()) { cmData = srcExif.findKey(Exiv2::ExifKey("Exif.Image.ColorMatrix2")); } if (cmData != srcExif.end() && cmData->count() == 3*colors) { for (int c = 0; c < colors; ++c) { for (int i = 0; i < 3; ++i) { camXyz[c][i] = 0.0; for (int j = 0; j < colors; ++j) { camXyz[c][i] += cc[c][j] * cmData->toFloat(j*3 + i) * xyz[i]; } } } } } catch (Exiv2::Error & e) { Log::debug("Could not load camXyz values from metadata: ", e.what()); } }
int RemoveGPSExif(const char* File, int NoChangeMtime) { struct stat statbuf; struct stat statbuf2; struct utimbuf utb; if (NoChangeMtime) stat(File, &statbuf); // Open the file and start reading. Exiv2::Image::AutoPtr Image; try { Image = Exiv2::ImageFactory::open(File); } catch (Exiv2::Error e) { DEBUGLOG("Failed to open file %s.\n", File); return 0; } Image->readMetadata(); if (Image.get() == NULL) { // It failed if we got here. DEBUGLOG("Failed to read file %s %s.\n", File, Exiv2::strError().c_str()); return 0; } Exiv2::ExifData &ExifInfo = Image->exifData(); if (ExifInfo.count() == 0) { DEBUGLOG("No EXIF tags in file %s.\n", File); return 0; } EraseGpsTags(ExifInfo); try { Image->writeMetadata(); } catch (Exiv2::Error e) { DEBUGLOG("Failed to write to file %s.\n", File); return 0; } if (NoChangeMtime) { stat(File, &statbuf2); utb.actime = statbuf2.st_atime; utb.modtime = statbuf.st_mtime; utime(File, &utb); } return 1; }
void Frame::save(std::string dir) { std::string path = dir + "/" + id; imwrite(path, *img); Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path); image->readMetadata(); Exiv2::ExifData &exifData = image->exifData(); std::stringstream ss; ss << std::setprecision(12) << data.lat << " " << data.lon << " " << data.altitude << " " << data.heading << " " << data.time; exifData["Exif.Photo.UserComment"] = ss.str(); image->writeMetadata(); }
char* ReadExifDate(const char* File, int* IncludesGPS) { // Open and read the file. Exiv2::Image::AutoPtr Image; try { Image = Exiv2::ImageFactory::open(File); } catch (Exiv2::Error e) { DEBUGLOG("Failed to open file %s.\n", File); return NULL; } Image->readMetadata(); if (Image.get() == NULL) { DEBUGLOG("Failed to read file %s %s.\n", File, Exiv2::strError().c_str()); return NULL; } Exiv2::ExifData &ExifRead = Image->exifData(); // Read the tag out. Exiv2::Exifdatum& Tag = ExifRead["Exif.Photo.DateTimeOriginal"]; // Check that the tag is not blank. std::string Value = Tag.toString(); if (Value.length() == 0) { // No date/time stamp. // Not good. // Just return - above us will handle it. return NULL; } // Copy the tag and return that. char* Copy = strdup(Value.c_str()); // Check if we have GPS tags. Exiv2::Exifdatum& GPSData = ExifRead["Exif.GPSInfo.GPSLatitude"]; if (GPSData.count() < 3) { // No valid GPS data. *IncludesGPS = 0; } else { // Seems to include GPS data... *IncludesGPS = 1; } // Now return, passing a pointer to the date string. return Copy; // It's up to the caller to free this. }
// Reads metadata from given file Exiv2::ExifData *FlickrDownload::readExifData(QString file){ try{ Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open( file.toStdString().c_str()); image->readMetadata(); Exiv2::ExifData *data = new Exiv2::ExifData(); *data = image->exifData(); return data; } catch (Exiv2::Error& e) { qCritical("[Filechooser] %s", e.what()); return 0; } }
NegativeProcessor* NegativeProcessor::createProcessor(AutoPtr<dng_host> &host, const char *filename) { // ----------------------------------------------------------------------------------------- // Open and parse rawfile with libraw... AutoPtr<LibRaw> rawProcessor(new LibRaw()); int ret = rawProcessor->open_file(filename); if (ret != LIBRAW_SUCCESS) { rawProcessor->recycle(); std::stringstream error; error << "LibRaw-error while opening rawFile: " << libraw_strerror(ret); throw std::runtime_error(error.str()); } ret = rawProcessor->unpack(); if (ret != LIBRAW_SUCCESS) { rawProcessor->recycle(); std::stringstream error; error << "LibRaw-error while unpacking rawFile: " << libraw_strerror(ret); throw std::runtime_error(error.str()); } // ----------------------------------------------------------------------------------------- // ...and libexiv2 Exiv2::Image::AutoPtr rawImage; try { rawImage = Exiv2::ImageFactory::open(filename); rawImage->readMetadata(); } catch (Exiv2::Error& e) { std::stringstream error; error << "Exiv2-error while opening/parsing rawFile (code " << e.code() << "): " << e.what(); throw std::runtime_error(error.str()); } // ----------------------------------------------------------------------------------------- // Identify and create correct processor class if (rawProcessor->imgdata.idata.dng_version != 0) { try {return new DNGprocessor(host, rawProcessor.Release(), rawImage);} catch (dng_exception &e) { std::stringstream error; error << "Cannot parse source DNG-file (code " << e.ErrorCode() << ")"; throw std::runtime_error(error.str()); } } else if (!strcmp(rawProcessor->imgdata.idata.model, "ILCE-7")) return new ILCE7processor(host, rawProcessor.Release(), rawImage); else if (!strcmp(rawProcessor->imgdata.idata.make, "FUJIFILM")) return new FujiProcessor(host, rawProcessor.Release(), rawImage); return new VariousVendorProcessor(host, rawProcessor.Release(), rawImage); }
bool ExifHasher::HashExif(const std::string& path, unsigned char* sha1_hash) const { FD fd; sys_call_rv(fd, open, path.c_str(), O_RDONLY); struct stat stat_buf; sys_call(fstat, fd, &stat_buf); void* memblock; sys_call2_rv(NULL, memblock, mmap, NULL, stat_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); auto bytes = static_cast<const unsigned char*>(memblock); Exiv2::Image::AutoPtr image; try { image = Exiv2::ImageFactory::open(bytes, stat_buf.st_size); } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; return false; } if (image.get() != 0) image->readMetadata(); else std::cerr << "Warning: EXIF not found in: " << path << std::endl; sys_call(munmap, memblock, stat_buf.st_size); fd.Close(); if (image.get() == 0) return false; const auto& exifData = image->exifData(); if (!exifData.empty()) { std::ostringstream oss; auto end = exifData.end(); for (auto i = exifData.begin(); i != end; ++i) { // std::cerr << i->key() << " (" << i->count() << ")" << ": " << // i->value() << std::endl; oss << i->key() << i->value(); } const std::string& exif_str = oss.str(); SHA1(reinterpret_cast<const unsigned char*>(exif_str.c_str()), exif_str.size(), sha1_hash); return true; } else { std::cerr << "Warning: EXIF not found in: " << path << std::endl; } return false; }
// Saves Exifdata to given file void FlickrUpload::saveExifData(Exiv2::ExifData *exifData, QByteArray *image){ try { Exiv2::Image::AutoPtr destImage = Exiv2::ImageFactory::open( (Exiv2::byte*)image->constData(), (long)image->size()); destImage->setExifData(*exifData); destImage->writeMetadata(); // get updated image data Exiv2::BasicIo& rawio = destImage->io(); Exiv2::DataBuf dbuf = rawio.read( rawio.size() ); image->clear(); image->append(QByteArray::fromRawData((char*)dbuf.pData_, dbuf.size_)); } catch (Exiv2::Error& e) { qCritical("[SaveFile] %s", e.what()); } }
void ImageView::saveImage() { Exiv2::Image::AutoPtr image; bool exifError = false; if (newImage) { saveImageAs(); return; } setFeedback(tr("Saving...")); try { image = Exiv2::ImageFactory::open(currentImageFullPath.toStdString()); image->readMetadata(); } catch (Exiv2::Error &error) { exifError = true; } QImageReader imgReader(currentImageFullPath); if (!displayPixmap.save(currentImageFullPath, imgReader.format().toUpper(), GData::defaultSaveQuality)) { QMessageBox msgBox; msgBox.critical(this, tr("Error"), tr("Failed to save image.")); return; } if (!exifError) { try { image->writeMetadata(); } catch (Exiv2::Error &error) { QMessageBox msgBox; msgBox.critical(this, tr("Error"), tr("Failed to save Exif metadata.")); } } reload(); setFeedback(tr("Image saved.")); }
int main(int argc, char* const argv[]) try { if (argc != 2) { std::cout << "Usage: " << argv[0] << " file\n"; return 1; } std::string file(argv[1]); Exiv2::IptcData iptcData; iptcData["Iptc.Application2.Headline"] = "The headline I am"; iptcData["Iptc.Application2.Keywords"] = "Yet another keyword"; iptcData["Iptc.Application2.DateCreated"] = "2004-8-3"; iptcData["Iptc.Application2.Urgency"] = uint16_t(1); iptcData["Iptc.Envelope.ModelVersion"] = 42; iptcData["Iptc.Envelope.TimeSent"] = "14:41:0-05:00"; iptcData["Iptc.Application2.RasterizedCaption"] = "230 42 34 2 90 84 23 146"; iptcData["Iptc.0x0009.0x0001"] = "Who am I?"; Exiv2::StringValue value; value.read("very!"); iptcData["Iptc.Application2.Urgency"] = value; std::cout << "Time sent: " << iptcData["Iptc.Envelope.TimeSent"] << "\n"; // Open image file Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file); if (image.get() == 0) { std::string error(file); error += " : Could not read file or unknown image type"; throw Exiv2::Error(error); } // Read existing metdata (so that exif will be preserved) int rc = image->readMetadata(); if (rc) { std::string error = Exiv2::Image::strError(rc, file); throw Exiv2::Error(error); } // Replace Iptc data and write it back to the file image->setIptcData(iptcData); return image->writeMetadata(); } catch (Exiv2::Error& e) { std::cout << "Caught Exiv2 exception '" << e << "'\n"; return -1; }
// uses the exiv2 class to readout the exifdata from images int ExifScout::showExifData(std::string a){ try { Ui_MainWindow::textEdit->clear(); std::cerr << "ImageFactory::open "; Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(a); std::cerr << "DONE\n"; assert(image.get() != 0); std::cerr << "image->readMetadata() "; image->readMetadata(); std::cerr << "DONE\n"; std::cerr << "Exiv2::ExifData& exifData = image->exifData() "; Exiv2::ExifData exifData = image->exifData(); std::cerr << "DONE\n"; cout << "Number of found exiv2 data: " << exifData.count() << endl; if (exifData.empty()) { Ui_MainWindow::textEdit->setPlainText("No Exif data found in file"); return 1; } Exiv2::ExifData::const_iterator end = exifData.end(); std::cerr << "Generate the exif-output "; QString output; for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) { std::string tagname = i->tagName(); if(tagname != std::string("MakerNote") and tagname.substr(0,2) != "0x"){ // Print out the exif-data in the QtextEdit Field std::ostringstream oss; oss << i->tagName() << ":\n " << i->value() << "\n"; output = output+(QString)oss.str().c_str(); } } std::cerr << "Done\n"; Ui_MainWindow::textEdit->setPlainText(output); return 0; } //catch (std::exception& e) { //catch (Exiv2::AnyError& e) { catch (Exiv2::Error& e) { std::cout << "Caught Exiv2 exception '" << e.what() << "'\n"; return -1; } }
void ThumbView::updateExifInfo(QString imageFullPath) { Exiv2::Image::AutoPtr exifImage; QString key; QString val; try { exifImage = Exiv2::ImageFactory::open(imageFullPath.toStdString()); exifImage->readMetadata(); } catch (Exiv2::Error &error) { return; } Exiv2::ExifData &exifData = exifImage->exifData(); if (!exifData.empty()) { Exiv2::ExifData::const_iterator end = exifData.end(); infoView->addTitleEntry("Exif"); for (Exiv2::ExifData::const_iterator md = exifData.begin(); md != end; ++md) { key = QString::fromUtf8(md->tagName().c_str()); val = QString::fromUtf8(md->print().c_str()); infoView->addEntry(key, val); } } Exiv2::IptcData &iptcData = exifImage->iptcData(); if (!iptcData.empty()) { Exiv2::IptcData::iterator end = iptcData.end(); infoView->addTitleEntry("IPTC"); for (Exiv2::IptcData::iterator md = iptcData.begin(); md != end; ++md) { key = QString::fromUtf8(md->tagName().c_str()); val = QString::fromUtf8(md->print().c_str()); infoView->addEntry(key, val); } } Exiv2::XmpData &xmpData = exifImage->xmpData(); if (!xmpData.empty()) { Exiv2::XmpData::iterator end = xmpData.end(); infoView->addTitleEntry("XMP"); for (Exiv2::XmpData::iterator md = xmpData.begin(); md != end; ++md) { key = QString::fromUtf8(md->tagName().c_str()); val = QString::fromUtf8(md->print().c_str()); infoView->addEntry(key, val); } } }
// ***************************************************************************** // Main int main(int argc, char* const argv[]) try { if (argc != 2) { std::cout << "Usage: " << argv[0] << " file\n"; return 1; } Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]); assert (image.get() != 0); image->readMetadata(); Exiv2::ExifData &exifData = image->exifData(); /* Exiv2 uses a CommentValue for Exif user comments. The format of the comment string includes an optional charset specification at the beginning: [charset=["]Ascii|Jis|Unicode|Undefined["] ]comment Undefined is used as a default if the comment doesn't start with a charset definition. Following are a few examples of valid comments. The last one is written to the file. */ exifData["Exif.Photo.UserComment"] = "charset=\"Unicode\" An Unicode Exif comment added with Exiv2"; exifData["Exif.Photo.UserComment"] = "charset=\"Undefined\" An undefined Exif comment added with Exiv2"; exifData["Exif.Photo.UserComment"] = "Another undefined Exif comment added with Exiv2"; exifData["Exif.Photo.UserComment"] = "charset=Ascii An ASCII Exif comment added with Exiv2"; std::cout << "Writing user comment '" << exifData["Exif.Photo.UserComment"] << "' back to the image\n"; image->writeMetadata(); return 0; } catch (Exiv2::AnyError& e) { std::cout << "Caught Exiv2 exception '" << e << "'\n"; return -1; }
int main(int argc, char* const argv[]) try { if (argc != 2) { std::cout << "Usage: " << argv[0] << " file\n"; return 1; } Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]); assert(image.get() != 0); image->readMetadata(); Exiv2::XmpData xmpData; Exiv2::copyExifToXmp(image->exifData(), xmpData); Exiv2::ExifData exifData; Exiv2::copyXmpToExif(xmpData, exifData); image->setXmpData(xmpData); image->setExifData(exifData); image->writeMetadata(); return 0; } catch (Exiv2::AnyError& e) { std::cout << "Caught Exiv2 exception '" << e << "'\n"; return -1; }
bool ptImageHelper::TransferExif(const QString ASourceFile, const QString ATargetFile) { if (ASourceFile == ATargetFile || ASourceFile.trimmed().isEmpty() || ATargetFile.trimmed().isEmpty()) return false; try { if (Exiv2::ImageFactory::getType(ASourceFile.toLocal8Bit().data()) == Exiv2::ImageType::none) return false; Exiv2::Image::AutoPtr hSourceImage = Exiv2::ImageFactory::open(ASourceFile.toLocal8Bit().data()); if (!hSourceImage.get()) return false; hSourceImage->readMetadata(); Exiv2::Image::AutoPtr hTargetImage = Exiv2::ImageFactory::open(ATargetFile.toLocal8Bit().data()); hTargetImage->clearMetadata(); hTargetImage->setMetadata(*hSourceImage); hTargetImage->writeMetadata(); return true; } catch (Exiv2::AnyError& Error) { if (Settings->GetInt("JobMode") == 0) { ptMessageBox::warning(0 ,"Exiv2 Error","No exif data written!\nCaught Exiv2 exception '" + QString(Error.what()) + "'\n"); } else { std::cout << "Caught Exiv2 exception '" << Error << "'\n"; } } return false; }
void ImageView::saveImageAs() { Exiv2::Image::AutoPtr exifImage; Exiv2::Image::AutoPtr newExifImage; bool exifError = false; setCursorHiding(false); QString fileName = QFileDialog::getSaveFileName(this, tr("Save image as"), currentImageFullPath, tr("Images") + " (*.jpg *.jpeg *.jpe *.png *.bmp *.ppm *.pgm *.pbm *.xbm *.xpm)"); if (!fileName.isEmpty()) { try { exifImage = Exiv2::ImageFactory::open(currentImageFullPath.toStdString()); exifImage->readMetadata(); } catch (Exiv2::Error &error) { exifError = true; } if (!displayPixmap.save(fileName, 0, GData::defaultSaveQuality)) { QMessageBox msgBox; msgBox.critical(this, tr("Error"), tr("Failed to save image.")); } else { if (!exifError) { try { newExifImage = Exiv2::ImageFactory::open(fileName.toStdString()); newExifImage->setMetadata(*exifImage); newExifImage->writeMetadata(); } catch (Exiv2::Error &error) { exifError = true; } } setFeedback(tr("Image saved.")); } } if (mainWindow->isFullScreen()) { setCursorHiding(true); } }
bool KExiv2::loadFromData(const QByteArray& imgData) const { if (imgData.isEmpty()) return false; try { Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open((Exiv2::byte*)imgData.data(), imgData.size()); d->filePath.clear(); image->readMetadata(); // Size and mimetype --------------------------------- d->pixelSize = QSize(image->pixelWidth(), image->pixelHeight()); d->mimeType = QString::fromLatin1(image->mimeType().c_str()); // Image comments --------------------------------- d->imageComments() = image->comment(); // Exif metadata ---------------------------------- d->exifMetadata() = image->exifData(); // Iptc metadata ---------------------------------- d->iptcMetadata() = image->iptcData(); #ifdef _XMP_SUPPORT_ // Xmp metadata ----------------------------------- d->xmpMetadata() = image->xmpData(); #endif // _XMP_SUPPORT_ return true; } catch( Exiv2::Error& e ) { d->printExiv2ExceptionError(QString::fromLatin1("Cannot load metadata using Exiv2 "), e); } catch(...) { qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2"; } return false; }
int ImgTagJson::literal() { Exiv2::Image::AutoPtr image; try { image = Exiv2::ImageFactory::open(fname); } catch (Exiv2::Error& e) { cerr << "Invalid file: " << fname << endl; return 6; } if (image.get() == 0) return 1; image->readMetadata(); JSONNODE *l = json_new(JSON_NODE); if (exif) { JSONNODE *e = this->genLitExif(image); if (e != NULL) json_push_back(l, e); } if (iptc) { JSONNODE *i = this->genLitIptc(image); if (i != NULL) json_push_back(l, i); } if (xmp) { JSONNODE *x = this->genLitXmp(image); if (x != NULL) json_push_back(l, x); } JSONNODE *chksum = getChkSum(); if (chksum != NULL) json_push_back(l, chksum); cout << json_write_formatted(l) << endl; json_delete(l); return 0; }