When IFD is missing, connect get_ifd() dictionary to Exif by radarhere · Pull Request #8230 · python-pillow/Pillow
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.