Skip to content

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
@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