Keep new IFDs when converting EXIF to bytes by radarhere · Pull Request #8635 · python-pillow/Pillow

Resolves #8634

The following code doesn't currently keep the new IFD tag when converting to bytes.

from PIL import Image
exif = Image.Exif()
ifd = exif.get_ifd(0x8769)
ifd[36864] = b"0220"
exif.tobytes()

This is because the new IFD is added to exif._ifds, but not exif._data. It makes sense to not save it to exif._data, because a tag value for the IFD would indicate the IFD offset, which only has meaning in byte format. However, exif._ifds isn't checked when converting to bytes, so the new IFD is forgotten.

This PR fixes that.