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

Getting IFD1 exif information #6777

Closed
cobi-s opened this issue Dec 4, 2022 · 2 comments · Fixed by #6748
Closed

Getting IFD1 exif information #6777

cobi-s opened this issue Dec 4, 2022 · 2 comments · Fixed by #6748
Labels

Comments

@cobi-s
Copy link

cobi-s commented Dec 4, 2022

Follow-up to #6641

A test image could be the following:
https://www.sun.ac.za/english/test-site/EXIF/sa.jpg

Please find below a code sample that uses the piexif library to extract all available exif information.

I wasn't able to retrieve the same information using only Pillow. In particular, not having the offsets to IFD1 and the embedded thumbnail makes it impossible (for me) to retrieve the tags from IFD1 as well as the raw data for the embedded thumbnail.

from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
import piexif

def lookup_tag(tag, ifd):
    lu = GPSTAGS if ifd == 'GPS' else TAGS
    try:
        return f'0x{tag:04x}: {lu[tag]}'
    except:
        return f'0x{tag:04x}: ???'

def print_dict(data):
    for ifd, val in data.items():
        print(f'{ifd}:')
        if ifd == 'thumbnail':
            print(f'    {len(val)} bytes')
        else:
            for tag in val:
                print(f'    {lookup_tag(tag, ifd)}: {val[tag]}')

path = 'sa.jpg'

with Image.open(path) as i:
    d = piexif.load(i.info['exif'])
    print_dict(d)
@cobi-s cobi-s mentioned this issue Dec 4, 2022
5 tasks
@radarhere radarhere added the Exif label Dec 4, 2022
@radarhere radarhere changed the title [Question] Getting IFD1 exif information with Pillow Getting IFD1 exif information Dec 4, 2022
@radarhere
Copy link
Member

I've added a commit to #6748. With that,

from PIL import Image, ExifTags
im = Image.open("sa.jpg")
print(im.getexif().get_ifd(ExifTags.IFD.IFD1))

gives

{513: 1370, 514: 5037, 259: 6, 296: 2, 274: 1, 531: 1, 282: 72.0, 283: 72.0}

@radarhere
Copy link
Member

radarhere commented Dec 6, 2022

I've added another commit to #6748. With that,

from PIL import Image, ExifTags
im = Image.open("sa.jpg")
im.get_child_images()[0].save("thumbnail.jpg")

gives

thumbnail

Those two changes should resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants