-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
How to get GPSInfo
and DateTimeOriginal
from .getexif()
?
#5863
Comments
Hi. My explanation is that GPSInfo is an IFD - https://www.awaresystems.be/imaging/tiff/tifftags/gpsifd.html. The int that you're seeing is not the data itself, but the offset to the data, in case anyone would like to access that. Instead, you can use See what you think of this. from PIL import Image
from PIL.Image import Exif
from PIL.ExifTags import TAGS, GPSTAGS
def get_exif(file_name) -> Exif:
image: Image.Image = Image.open(file_name)
return image.getexif()
def get_geo(exif):
for key, value in TAGS.items():
if value == "GPSInfo":
break
gps_info = exif.get_ifd(key)
return {
GPSTAGS.get(key, key): value
for key, value in gps_info.items()
}
if __name__ == '__main__':
exif = get_exif("Tests/images/exif_gps.jpg")
geo = get_geo(exif)
print(geo) |
You gave my response a thumbs up. Does that mean you're happy with this and the issue can be closed? |
@radarhere, I still can't understand behaviour of public exif method, e.g.: |
from PIL import Image
from PIL.Image import Exif
from PIL.ExifTags import TAGS
def get_exif(file_name) -> Exif:
image: Image.Image = Image.open(file_name)
return image.getexif()
def get_exif_ifd(exif):
for key, value in TAGS.items():
if value == "ExifOffset":
break
info = exif.get_ifd(key)
return {
TAGS.get(key, key): value
for key, value in info.items()
}
if __name__ == '__main__':
exif = get_exif("Tests/images/exif_gps.jpg")
print(get_exif_ifd(exif)) gives
|
Thanks! Now that's clear for me :) I'll rename the issue to help others find the explanation |
.getexif()
GPSInfo
and DateTimeOriginal
from .getexif()
?
I couldn't find this anywhere in the documentation. This works really well, thanks for sharing here. |
Bug from #1477 still actual for public
getexif
method.What did you do?
Trying to get valid GPSInfo data from EXIF:
What did you expect to happen?
Result
What actually happened?
What are your OS, Python and Pillow versions?
Workaround
Use
image._getexif()
instead ofimage.getexif()
Tests
So why the Pillow tests pass successfully?
That's why:
Pillow/Tests/test_file_jpeg.py
Lines 254 to 256 in bd00cd9
The text was updated successfully, but these errors were encountered: