Skip to content

Commit

Permalink
Do not ignore SyntaxError when saving EXIF data
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 7, 2024
1 parent c40bcbf commit 003f0a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Tests/test_file_avif.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def test_exif_save_argument(self, tmp_path: Path, bytes: bool) -> None:
def test_exif_invalid(self, tmp_path: Path) -> None:
with Image.open(TEST_AVIF_FILE) as im:
test_file = str(tmp_path / "temp.avif")
with pytest.raises(ValueError):
with pytest.raises(SyntaxError):
im.save(test_file, exif=b"invalid")

def test_xmp(self) -> None:
Expand Down
18 changes: 6 additions & 12 deletions src/PIL/AvifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down

0 comments on commit 003f0a3

Please sign in to comment.