pyexiv2 icon indicating copy to clipboard operation
pyexiv2 copied to clipboard

Adding tag description access to pyexiv2

Open ferdnyc opened this issue 1 year ago • 0 comments

A long time ago, in #10, @LeoHsiao1 expressed interest in adding access to tag description fields to pyexiv2, but had trouble accessing the relevant libexiv2 API.

Comment posted by @LeoHsiao1

Hi! I found that pyexiv2 can't edit the two tags you said:

>>> img.modify_exif({'Exif.Photo.MakerNote': 'test', 'Exif.Canon.ShotInfo': 'test'})  
>>> img.read_exif()['Exif.Photo.MakerNote'] 
''
>>> img.read_exif()['Exif.Canon.ShotInfo']  
''

I'm calling exiv2's API just like the example, but I don't know how to read tag description. I tried this Code:

    Exiv2::ExifData::const_iterator end = exifData.end();
    for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) {
        const char* tn = i->tagdesc();

But there was an error in compilation: 'tagdesc': not a member of 'exiv2:: exifdatum'

If you find that API, I can add it to pyexiv2.

Originally posted by @LeoHsiao1 in https://github.com/LeoHsiao1/pyexiv2/issues/10#issuecomment-586200536

Update

@LeoHsiao1: The reason that call didn't work is that the method for accessing the description text is tagDesc(), not tagdesc(), and it actually returns a std::string. So, this should work fine:

    Exiv2::ExifData::const_iterator end = exifData.end();
    for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) {
        std::string description(i->tagDesc());

Or even better, in the world of C++11:

    Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(file);
    image->readMetadata();
    Exiv2::ExifData &exifData = image->exifData();
    
    for (const auto& datum : exifData) {
        std::string description(datum.tagDesc());
        // ...
    }

ferdnyc avatar May 10 '24 19:05 ferdnyc