Skip to content

Commit

Permalink
Do not potentially call Exif tobytes() twice
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 14, 2024
1 parent 2eb9fb2 commit 938f413
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/PIL/AvifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,18 @@ def _save(
autotiling = bool(info.get("autotiling", tile_rows_log2 == tile_cols_log2 == 0))

icc_profile = info.get("icc_profile", im.info.get("icc_profile"))
exif_orientation = 1
if exif := info.get("exif"):
if isinstance(exif, Image.Exif):
exif_data = exif
exif = exif.tobytes()
else:
exif_data = Image.Exif()
exif_data.load(exif)
exif_orientation = exif_data.pop(ExifTags.Base.Orientation, 0)
if exif_orientation != 0:
if len(exif_data):
exif = exif_data.tobytes()
else:
exif = None
else:
exif_orientation = 0
if ExifTags.Base.Orientation in exif_data:
exif_orientation = exif_data.pop(ExifTags.Base.Orientation)
exif = exif_data.tobytes() if exif_data else b""
elif isinstance(exif, Image.Exif):
exif = exif_data.tobytes()

xmp = info.get("xmp")

Expand Down

0 comments on commit 938f413

Please sign in to comment.