Adding tag description access to pyexiv2
ferdnyc opened this issue · 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 #10 (comment)
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());
// ...
}
I'm very sorry, I didn't notice your issue in my inbox until now.
Thanks for the sample code!
I'll release a new version in the next few days.