Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

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

Open radarhere opened this issue 1 year ago • 0 comments

Resolves #8229

When calling Exif.get_ifd(), if the IFD is missing, an empty dictionary is returned. https://github.com/python-pillow/Pillow/blob/6a9acfa5ca2b3ba462b086e4af776993bbd94a72/src/PIL/Image.py#L4076

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 avatar Jul 13 '24 02:07 radarhere