QString exifDataToString(Exiv2::ExifData exifData) {
    if (exifData.empty()) {
        return QString(QObject::tr("No EXIF found"));
    }
    try {
        Exiv2::ExifData::const_iterator end = exifData.end();
        QString tmpExif, final;
        for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) {
            const char* tn = i->typeName();
            /*std::string str = 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->value()
                      << "\n";*/
            tmpExif = "<span style='color:#1cb495;'>" + QString::fromStdString(i->key()).split(".").at(2) + "</span>&emsp;" +
                      //QString::number(i->tag()) + "\t" +
                      //(tn ? tn : "Unknown") + "\t" +
                      //QString::number(i->count()) + "\t" +
                      QString::fromStdString(i->value().toString()) + "<br />";
            final.append(tmpExif);
        }
        return final;
    } catch(Exiv2::Error& e) {
// 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;
    }
}
// tries to find a specified exif tag in a specified file
QString ExifScout::getExifData(QString fname, QString etag){
    std::string filename = fname.toAscii().data();
    std::string exiftag = etag.toAscii().data();

    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
    assert(image.get() != 0);
    image->readMetadata();
    Exiv2::ExifData exifData = image->exifData();
    if (!exifData.empty()) {
        Exiv2::ExifData::const_iterator end = exifData.end();
        QString output;
        for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) {
            if(i->tagName()==exiftag){
                std::ostringstream oss;
                oss << i->value();
                return (QString)oss.str().c_str();
            }
        }
    }
    return NULL;
}
示例#4
0
int RenameMePhotos::openDirectory(std::string p, std::vector<std::pair<boost::filesystem::path, time_t> > &vec, bool recursive, bool clear)
{
	if(clear)
	{
		vec.clear();
	}
	// Var Declaration
	struct tm t;
	std::vector<boost::filesystem::path> vecTmp;
	std::pair<boost::filesystem::path, time_t> file;
	std::string strTmp;
	time_t timestamp;
	boost::filesystem::path path(p);

	Exiv2::ExifData exifData;
	Exiv2::Image::AutoPtr image;
	
	// Body
	if(exists(path))
	{
		if(is_directory(path))
		{		
			if(recursive)
			{
				std::copy(boost::filesystem::recursive_directory_iterator(path), boost::filesystem::recursive_directory_iterator(), std::back_inserter(vecTmp));
			}
			else
			{
				std::copy(boost::filesystem::directory_iterator(path), boost::filesystem::directory_iterator(), std::back_inserter(vecTmp));
			}

			for(std::vector<boost::filesystem::path>::const_iterator it(vecTmp.begin()); it != vecTmp.end(); it++)
			{
				if(!is_directory(*it))
				{
					image = Exiv2::ImageFactory::open((*it).c_str());
					if(image.get() != 0)
					{
						image->readMetadata();
						exifData = image->exifData();
						if(!exifData.empty())
						{
							strTmp = exifData["Exif.Photo.DateTimeOriginal"].toString();
							strptime(strTmp.c_str(), "%Y:%m:%d %H:%M:%S", &t);
							t.tm_isdst = -1;
							timestamp = mktime(&t);
							file = std::make_pair(*it, timestamp);
							vec.push_back(file);
						}
						else
						{
							// Error for at least an image in metadata
						}
					}
				}
			}
		}
		else
		{
			// Error 2: The selected path is not a directory
		}
	}
	else
	{
		// Error 1: There is no such path
	}
	return 1;
}
示例#5
0
bool ptImageHelper::ReadExif(const QString        &AFileName,
                             Exiv2::ExifData      &AExifData,
                             std::vector<uint8_t> &AExifBuffer)
{
  if (AFileName.trimmed().isEmpty()) return false;

  try {
    if (Exiv2::ImageFactory::getType(AFileName.toLocal8Bit().data()) == Exiv2::ImageType::none)
      return false;

    Exiv2::Image::AutoPtr hImage = Exiv2::ImageFactory::open(AFileName.toLocal8Bit().data());

    if (!hImage.get()) return false;

    hImage->readMetadata();

    AExifData = hImage->exifData();
    if (AExifData.empty()) {
      ptLogWarning(ptWarning_Argument, "No Exif data found in %s", AFileName.toLocal8Bit().data());
      return false;
    }

    Exiv2::ExifData::iterator Pos;
    size_t                    Size;

#if EXIV2_TEST_VERSION(0,17,91)   /* Exiv2 0.18-pre1 */
    Exiv2::Blob               Blob;
    Exiv2::ExifParser::encode(Blob, Exiv2::bigEndian, AExifData);
    Size = Blob.size();
#else
    Exiv2::DataBuf            Buf(AExifData.copy());
    Size = Buf.size_;
#endif

    /* If buffer too big for JPEG, try deleting some stuff. */
    if (Size + CExifHeader.size() > CMaxHeaderLength) {
      if ((Pos = AExifData.findKey(Exiv2::ExifKey("Exif.Photo.MakerNote"))) != AExifData.end() ) {
        AExifData.erase(Pos);
        ptLogWarning(ptWarning_Argument, "Exif buffer too big, erasing Exif.Photo.MakerNote");
#if EXIV2_TEST_VERSION(0,17,91)   /* Exiv2 0.18-pre1 */
        Exiv2::ExifParser::encode(Blob, Exiv2::bigEndian, AExifData);
        Size = Blob.size();
#else
        Buf  = AExifData.copy();
        Size = Buf.size_;
#endif
      }
    }

    // Erase embedded thumbnail if needed
    if (Settings->GetInt("EraseExifThumbnail") ||
        (Size + CExifHeader.size()) > CMaxHeaderLength ) {
#if EXIV2_TEST_VERSION(0,17,91)   /* Exiv2 0.18-pre1 */
      Exiv2::ExifThumb Thumb(AExifData);
      Thumb.erase();
#else
      AExifData.eraseThumbnail();
#endif

      if (!Settings->GetInt("EraseExifThumbnail"))
        ptLogWarning(ptWarning_Argument, "Exif buffer too big, erasing Thumbnail");

#if EXIV2_TEST_VERSION(0,17,91)   /* Exiv2 0.18-pre1 */
      Exiv2::ExifParser::encode(Blob, Exiv2::bigEndian, AExifData);
      Size = Blob.size();
#else
      Buf = AExifData.copy();
      Size = Buf.size_;
#endif
    }

    AExifBuffer.clear();
    AExifBuffer.insert(AExifBuffer.end(),
                       CExifHeader.begin(),
                       CExifHeader.end());
#if EXIV2_TEST_VERSION(0,17,91)   /* Exiv2 0.18-pre1 */
    AExifBuffer.insert(AExifBuffer.end(),
                       Blob.begin(),
                       Blob.end());
#else
    // old code will currently not compile
    memcpy(AExifBuffer+sizeof(ExifHeader), Buf.pData_, Buf.size_);
#endif
    return true;

  } catch(Exiv2::Error& Error) {
    // Exiv2 errors are in this context hopefully harmless
    // (unsupported tags etc.)

    ptLogWarning(ptWarning_Exiv2,"Exiv2 : %s\n",Error.what());
  }
  return false;
}