Return exif information as a dictionary.
(img_pil: Image.Image)
| 82 | |
| 83 | |
| 84 | def extract_exif(img_pil: Image.Image) -> dict[str, Any]: |
| 85 | """Return exif information as a dictionary.""" |
| 86 | # Get full exif description from get_ifd(0x8769): |
| 87 | # cf https://pillow.readthedocs.io/en/stable/releasenotes/8.2.0.html#image-getexif-exif-and-gps-ifd # noqa |
| 88 | img_exif = img_pil.getexif().get_ifd(0x8769) |
| 89 | exif_dict = {ExifTags.TAGS[k]: v for k, v in img_exif.items() if k in ExifTags.TAGS} |
| 90 | |
| 91 | # https://pillow.readthedocs.io/en/stable/_modules/PIL/TiffTags.html# # noqa |
| 92 | tiff_tags = img_pil.getexif() |
| 93 | tiff_dict = {TiffTags.TAGS_V2[k].name: v for k, v in tiff_tags.items() if k in TiffTags.TAGS_V2} |
| 94 | return {**exif_dict, **tiff_dict} |
| 95 | |
| 96 | |
| 97 | def convert_focallength(width: float, height: float, f_mm: float = 30) -> float: |