Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing arrays into exif segment is not working #12

Closed
xavieldar opened this issue Feb 28, 2020 · 3 comments
Closed

Writing arrays into exif segment is not working #12

xavieldar opened this issue Feb 28, 2020 · 3 comments
Labels

Comments

@xavieldar
Copy link

Some Exif tags store a list of values, such as GPS latitude and longitude, which take a list of three rationals to store the angle in a "degrees minutes seconds" format.

For example, one would expect to be able to write something in the form

image.modify_exif({
    'Exif.GPSInfo.GPSLongitude': ['30/1', '50/1', '12345/1000'],
    'Exif.GPSInfo.GPSLatitude': ['30/1', '50/1', '12345/1000'],
})

and read back successfully the values.

Looking at the api C++ code, arrays seems to be supported in the XMP segments. I believe that porting the same behaviour to the exif part should be straightforward.

Thanks for the good work!

@LeoHsiao1
Copy link
Owner

LeoHsiao1 commented Feb 28, 2020

Hi!
There are many types of metadata, so I didn't try to see if each tag could be modified.

I tried to read the tag you mentioned and found it was like this:

>>> import pyexiv2
>>> img = pyexiv2.Image(r'C:\Users\Leo\Desktop\IMG_20200105_115821.jpg')
>>> img.read_exif()['Exif.GPSInfo.GPSLongitude']
'114/1 2/1 426696/10000'

So I modified it in the same format. It works:

>>> img.modify_exif({'Exif.GPSInfo.GPSLongitude': '200/1 2/1 400000/10000'})
>>> img.read_exif()['Exif.GPSInfo.GPSLongitude']
'200/1 2/1 400000/10000'

Next, you just need to convert it from string to list:

>>> '200/1 2/1 400000/10000'.split(' ')
['200/1', '2/1', '400000/10000']
>>> ' '.join(['200/1', '2/1', '400000/10000'])
'200/1 2/1 400000/10000'

Does that solve your problem?

@xavieldar
Copy link
Author

Hi,

Thanks for the quick answer. Actually, that works, thanks!

I though I tried that, but I was converting Fraction object into string directly with fractions.Fraction.__str__(), which does not print out the denominator when equals to 1, which gave me:
'30 50 12345/1000' instead of '30/1 50/1 12345/1000', and would not work… This is fixed on my side and I can properly geotag images.

Thanks.

@github-actions
Copy link

github-actions bot commented Aug 2, 2021

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

@github-actions github-actions bot locked and limited conversation to collaborators Aug 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants