diff --git a/src/PIL/AvifImagePlugin.py b/src/PIL/AvifImagePlugin.py index 8746666bf1d..7bd1e84c58d 100644 --- a/src/PIL/AvifImagePlugin.py +++ b/src/PIL/AvifImagePlugin.py @@ -96,20 +96,21 @@ def _open(self) -> None: if icc: self.info["icc_profile"] = icc - if exif: - self.info["exif"] = exif if xmp: self.info["xmp"] = xmp - if exif_orientation != 1 or exif is not None: + if exif_orientation != 1 or exif: exif_data = Image.Exif() - orig_orientation = 1 - if exif is not None: + if exif: exif_data.load(exif) - orig_orientation = exif_data.get(ExifTags.Base.Orientation, 1) - if exif_orientation != orig_orientation: + original_orientation = exif_data.get(ExifTags.Base.Orientation, 1) + else: + original_orientation = 1 + if exif_orientation != original_orientation: exif_data[ExifTags.Base.Orientation] = exif_orientation - self.info["exif"] = exif_data.tobytes() + exif = exif_data.tobytes() + if exif: + self.info["exif"] = exif def seek(self, frame: int) -> None: if not self._seek_check(frame):