LeoHsiao1 / pyexiv2

Read and write image metadata, including EXIF, IPTC, XMP, ICC Profile.
GNU General Public License v3.0
197 stars 39 forks source link

iptc.get() return a string in some cases #52

Closed xDEADC0DE closed 3 years ago

xDEADC0DE commented 3 years ago

Thanks for this amazing package!

I’m having a minor issue when reading the IPTC tags (or keywords) of an image, using the following code:

img = pyexiv2.Image(localFile)
iptc = img.read_iptc()
iptc_tags = iptc.get('Iptc.Application2.Keywords') or list()
iptc_tags.append('a new tag')

If the image doesn’t have tags, or if it has multiple tags then the code works fine.

However, if the image has exactly 1 tag, then iptc.get('Iptc.Application2.Keywords') returns a string instead of list.

Is there an option to have iptc.get() always return a list?

LeoHsiao1 commented 3 years ago

Thank you for your feedback. This problem is due to:: Iptc.Application2.Keywords is of type String by default. If it has multiple values, pyexiv2 converts it to List type. In three days, I will release a new version that will proactively convert some of these fields to list types.

xDEADC0DE commented 3 years ago

Great! I was afraid there was something wrong with my code, or an option I hadn’t seen :) Thanks

LeoHsiao1 commented 3 years ago

Hi! I just released v2.5.0. It took me longer than expected to add other features.

xDEADC0DE commented 3 years ago

Great! Thanks for your help

github-actions[bot] commented 2 years ago

This issue has been automatically closed because there has been no activity for a month.