Fix EXIF serialization issue due to mismatch between legacy and new mode

This commit is contained in:
Kasper Nielsen 2019-12-02 15:33:30 +01:00 committed by Andrew Murray
parent 29fee8fc43
commit a896a4fdff
3 changed files with 10 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 MiB

View File

@ -307,3 +307,10 @@ def test_exif_transpose():
"Tests/images/hopper_orientation_" + str(i) + ext "Tests/images/hopper_orientation_" + str(i) + ext
) as orientation_im: ) as orientation_im:
check(orientation_im) check(orientation_im)
def test_exif_transpose_metadata_error():
with Image.open("Tests/images/exif_transpose_rational_mismatch.jpg") as img:
transposed = ImageOps.exif_transpose(img)
parsed_exif = transposed.getexif()
assert parsed_exif[318] == [(313, 1000), (329, 1000)]

View File

@ -258,8 +258,9 @@ def _accept(prefix):
def _limit_rational(val, max_val): def _limit_rational(val, max_val):
inv = abs(val) > 1 ifd_val = IFDRational(val[0], val[1]) if isinstance(val, tuple) else val
n_d = IFDRational(1 / val if inv else val).limit_rational(max_val) inv = abs(ifd_val) > 1
n_d = IFDRational(1 / ifd_val if inv else ifd_val).limit_rational(max_val)
return n_d[::-1] if inv else n_d return n_d[::-1] if inv else n_d