Ejemplo n.º 1
0
int main(int argc, char* const argv[])
try {
    
    if (argc != 2) {
        std::cout << "Usage: " << argv[0] << " file\n";
        return 1;
    }
    
    const char* path=argv[1];
        
    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path);
    assert(image.get() != 0);
    image->readMetadata();
        
    Jzon::Object root;

    const char*    FS="FS";
    Jzon::Object      fs  ;
    root.Add      (FS,fs) ;
    fileSystemPush(path,root.Get(FS));
    
	Exiv2::ExifData &exifData = image->exifData();
    for ( ExifData::const_iterator i = exifData.begin(); i != exifData.end() ; ++i ) {
        std::string   key ;
        push(objectForKey(i->key(),key,root),key,i);
    }

	Exiv2::IptcData &iptcData = image->iptcData();
    for (Exiv2::IptcData::const_iterator i = iptcData.begin(); i != iptcData.end(); ++i) {
        std::string key ;
        push(objectForKey(i->key(),key,root),key,i);
    }

	Exiv2::XmpData  &xmpData  = image->xmpData();
    for (Exiv2::XmpData::const_iterator i = xmpData.begin(); i != xmpData.end(); ++i) {
        std::string key ;
        push(objectForKey(i->key(),key,root),key,i);
    }
/*
    This is only for testing long paths    
    {
    	ExifData::const_iterator i = exifData.begin();
    	std::string key;
    	push(objectForKey("This.Is.A.Rather.Long.Path.Key",key,root),key,i);
    }
*/        
    Jzon::Writer writer(root,Jzon::StandardFormat);
    writer.Write();
    std::cout << writer.GetResult() << std::endl;
    return 0;
}
        
//catch (std::exception& e) {
//catch (Exiv2::AnyError& e) {
catch (Exiv2::Error& e) {
    std::cout << "Caught Exiv2 exception '" << e.what() << "'\n";
    return -1;
}
Ejemplo n.º 2
0
// This is weird because iptc and exif have not been "unified". Once
// they are unified, this DLL should not have to know
// about either... just generic images, keys, values, etc.
//
// buffsize should be the total size of *buff (including space for null)
// Note that if there is more than one entry (for some IPTC datasets) this
// returns the first one found. Currently no way to get the others.
// Returns 0 on success
EXIVSIMPLE_API int ReadMeta(HIMAGE img, const char *key, char *buff, int buffsize)
{
    assert(img && key && buff);
    if (img==0 || key==0 || buff==0 || buffsize==0) return -1;
    ImageWrapper *imgWrap = (ImageWrapper*)img;
    int rc = 2;

    Exiv2::IptcData &iptcData = imgWrap->image->iptcData();
    Exiv2::ExifData &exifData = imgWrap->image->exifData();

    try {
        // First try iptc
        Exiv2::IptcKey iptcKey(key);
        rc = 1;
        Exiv2::IptcData::const_iterator iter = iptcData.findKey(iptcKey);
        if (iter != iptcData.end()) {
            strncpy(buff, iter->value().toString().c_str(), buffsize);
            buff[buffsize-1] = 0;
            rc = 0;
        }
    } 
    catch(const Exiv2::AnyError&) {
    }

    if (rc) {
        // No iptc value, so try exif
        try {
            Exiv2::ExifKey exifKey(key);
            rc = 1;
            Exiv2::ExifData::const_iterator iter = exifData.findKey(exifKey);
            if (iter != exifData.end()) {
                strncpy(buff, iter->value().toString().c_str(), buffsize);
                buff[buffsize-1] = 0;
                rc = 0;
            }
        }
        catch(const Exiv2::AnyError&) {
        }
    }

    return rc;
}
Ejemplo n.º 3
0
EXIVSIMPLE_API int EnumMeta(HIMAGE img, METAENUMPROC proc, void *user)
{
    assert(img && proc);
    if (img==0 || proc==0) return -1;
    ImageWrapper *imgWrap = (ImageWrapper*)img;
    bool more = true;

    Exiv2::IptcData &iptcData = imgWrap->image->iptcData();
    Exiv2::ExifData &exifData = imgWrap->image->exifData();

    Exiv2::IptcData::const_iterator iend = iptcData.end();
    for (Exiv2::IptcData::const_iterator i = iptcData.begin(); 
            i != iend && more; ++i) {
        more = proc(i->key().c_str(), i->value().toString().c_str(), user);
    }

    Exiv2::ExifData::const_iterator eend = exifData.end();
    for (Exiv2::ExifData::const_iterator e = exifData.begin();
            e != eend && more; ++e) {
        more = proc(e->key().c_str(), e->value().toString().c_str(), user);
    }

    return 0;
}
Ejemplo n.º 4
0
JSONNODE *ImgTagJson::genLitIptc(const Exiv2::Image::AutoPtr & image)
{
    Exiv2::IptcData &data = image->iptcData();
    data.sortByKey();

    if (data.empty()) return NULL;

    Exiv2::IptcData::const_iterator end = data.end();

    JMAP *grpmap = new JMAP();
    JSONNODE *tree = json_new(JSON_NODE);
    for (Exiv2::IptcData::const_iterator i = data.begin(); i != end; i++)
    {
        JSONNODE *grp;
        if (grpmap->find(i->groupName()) == grpmap->end())
        {
            grp = json_new(JSON_NODE);
            json_set_name(grp, i->groupName().c_str());
            grpmap->insert(JMAP::value_type(i->groupName(), grp)); 
        }
        else
           grp = (grpmap->find(i->groupName()))->second;

        Exiv2::IptcData::const_iterator nxt = i + 1;
        if ((nxt != data.end()) && (i->key() == nxt->key()))
        {
            //cout << "Array Elem! " << i->key() << endl;
            JSONNODE *arr = json_new(JSON_ARRAY);
            json_set_name(arr, i->tagName().c_str());
            json_push_back(arr, json_new_a((i->tagName()).c_str(),
                (i->print()).c_str()));

            while ((nxt != data.end()) && (nxt->key() == i->key()))
            {
                json_push_back(arr, json_new_a((nxt->tagName()).c_str(),
                    (nxt->print()).c_str()));
                nxt++;
            }
            json_push_back(grp, arr);
            if (nxt == data.end()) break;
            i = nxt - 1;
        }
        else
        {
            json_push_back(grp, json_new_a((i->tagName()).c_str(),
                (i->print()).c_str()));
        }
    }
    JMAP::iterator it;
    for(it = grpmap->begin(); it != grpmap->end(); it++)
    {
        json_push_back(tree, it->second);
        grpmap->erase(it);
    }
        //cout << it->first << endl;
    delete grpmap;
    //cout << json_write_formatted(tree) << endl;
    json_set_name(tree, "iptc");
    return tree;
}