Skip to content

Commit 938f413

Browse files
committed
Do not potentially call Exif tobytes() twice
1 parent 2eb9fb2 commit 938f413

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/PIL/AvifImagePlugin.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,18 @@ def _save(
180180
autotiling = bool(info.get("autotiling", tile_rows_log2 == tile_cols_log2 == 0))
181181

182182
icc_profile = info.get("icc_profile", im.info.get("icc_profile"))
183+
exif_orientation = 1
183184
if exif := info.get("exif"):
184185
if isinstance(exif, Image.Exif):
185186
exif_data = exif
186-
exif = exif.tobytes()
187187
else:
188188
exif_data = Image.Exif()
189189
exif_data.load(exif)
190-
exif_orientation = exif_data.pop(ExifTags.Base.Orientation, 0)
191-
if exif_orientation != 0:
192-
if len(exif_data):
193-
exif = exif_data.tobytes()
194-
else:
195-
exif = None
196-
else:
197-
exif_orientation = 0
190+
if ExifTags.Base.Orientation in exif_data:
191+
exif_orientation = exif_data.pop(ExifTags.Base.Orientation)
192+
exif = exif_data.tobytes() if exif_data else b""
193+
elif isinstance(exif, Image.Exif):
194+
exif = exif_data.tobytes()
198195

199196
xmp = info.get("xmp")
200197

0 commit comments

Comments
 (0)