diff --git a/src/PIL/AvifImagePlugin.py b/src/PIL/AvifImagePlugin.py index c92e2534ef9..d9d2850037e 100644 --- a/src/PIL/AvifImagePlugin.py +++ b/src/PIL/AvifImagePlugin.py @@ -169,21 +169,15 @@ def _save( icc_profile = info.get("icc_profile", im.info.get("icc_profile")) exif = info.get("exif", im.info.get("exif")) - if isinstance(exif, Image.Exif): - exif = exif.tobytes() - exif_orientation = 0 if exif: - exif_data = Image.Exif() - try: - exif_data.load(exif) - except SyntaxError: - pass + if isinstance(exif, Image.Exif): + exif_data = exif + exif = exif.tobytes() else: - orientation_tag = next( - k for k, v in ExifTags.TAGS.items() if v == "Orientation" - ) - exif_orientation = exif_data.get(orientation_tag) or 0 + exif_data = Image.Exif() + exif_data.load(exif) + exif_orientation = exif_data.get(ExifTags.Base.Orientation, 0) xmp = info.get("xmp", im.info.get("xmp") or im.info.get("XML:com.adobe.xmp"))