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

Merged
merged 2 commits into from
Sep 4, 2024

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
@hugovk hugovk merged commit e2c1357 into python-pillow:main Sep 4, 2024
51 checks passed
@radarhere radarhere deleted the exif_get_ifd branch September 4, 2024 21:20
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?
2 participants