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

When IFD is missing, connect get_ifd() dictionary to Exif #8230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

radarhere
Copy link
Member

Resolves #8229

When calling Exif.get_ifd(), if the IFD is missing, an empty dictionary is returned.

ifd = self._ifds.get(tag, {})

However, that dictionary is not stored in the Exif instance, making for an inconsistent user experience.

If an IFD exists,

from PIL import Image
im = Image.open("/Users/andrewmurray/pillow/Pillow/Tests/images/flower.jpg")
exif = im.getexif()
ifd = exif.get_ifd(0x8769)
ifd[36864] = b'1'

print(exif.get_ifd(0x8769).get(36864))  # b'1'

If an IFD does not exist,

from PIL import Image
im = Image.open("/Users/andrewmurray/pillow/Pillow/Tests/images/hopper.jpg")
exif = im.getexif()
ifd = exif.get_ifd(0x8769)
ifd[36864] = b'1'

print(exif.get_ifd(0x8769).get(36864))  # None

This connects the created empty dictionary, so that the second code example behaves like the first.

@radarhere radarhere added the Exif label Jul 13, 2024
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 this pull request may close these issues.

Possible to add an IFD to an image's EXIF data?
1 participant