Skip to content

Commit

Permalink
Changed to ImageFileDirectory_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jun 3, 2020
1 parent ba58ae7 commit ccac9e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
23 changes: 18 additions & 5 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_exif_gps(self):
gps_index = 34853
expected_exif_gps = {
0: b"\x00\x00\x00\x01",
2: (4294967295, 1),
2: 4294967295,
5: b"\x01",
30: 65535,
29: "1999:99:99 99:99:99",
Expand All @@ -241,7 +241,7 @@ def test_exif_rollback(self):
36867: "2099:09:29 10:10:10",
34853: {
0: b"\x00\x00\x00\x01",
2: (4294967295, 1),
2: 4294967295,
5: b"\x01",
30: 65535,
29: "1999:99:99 99:99:99",
Expand All @@ -253,11 +253,11 @@ def test_exif_rollback(self):
271: "Make",
272: "XXX-XXX",
305: "PIL",
42034: ((1, 1), (1, 1), (1, 1), (1, 1)),
42034: (1, 1, 1, 1),
42035: "LensMake",
34856: b"\xaa\xaa\xaa\xaa\xaa\xaa",
282: (4294967295, 1),
33434: (4294967295, 1),
282: 4294967295,
33434: 4294967295,
}

with Image.open("Tests/images/exif_gps.jpg") as im:
Expand Down Expand Up @@ -647,6 +647,19 @@ def test_invalid_exif(self):
# OSError for unidentified image.
assert im.info.get("dpi") == (72, 72)

def test_exif_x_resolution(self, tmp_path):
with Image.open("Tests/images/flower.jpg") as im:
exif = im.getexif()
assert exif[282] == 180

out = str(tmp_path / "out.jpg")
with pytest.warns(None) as record:
im.save(out, exif=exif)
assert len(record) == 0

with Image.open(out) as reloaded:
assert reloaded.getexif()[282] == 180

def test_invalid_exif_x_resolution(self):
# When no x or y resolution is defined in EXIF
with Image.open("Tests/images/invalid-exif-without-x-resolution.jpg") as im:
Expand Down
6 changes: 3 additions & 3 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3248,7 +3248,7 @@ def __init__(self):

def _fixup(self, value):
try:
if len(value) == 1 and not isinstance(value, dict):
if len(value) == 1 and isinstance(value, tuple):
return value[0]
except Exception:
pass
Expand All @@ -3269,7 +3269,7 @@ def _get_ifd_dict(self, tag):
else:
from . import TiffImagePlugin

info = TiffImagePlugin.ImageFileDirectory_v1(self.head)
info = TiffImagePlugin.ImageFileDirectory_v2(self.head)
info.load(self.fp)
return self._fixup_dict(info)

Expand All @@ -3294,7 +3294,7 @@ def load(self, data):
# process dictionary
from . import TiffImagePlugin

self._info = TiffImagePlugin.ImageFileDirectory_v1(self.head)
self._info = TiffImagePlugin.ImageFileDirectory_v2(self.head)
self.endian = self._info._endian
self.fp.seek(self._info.next)
self._info.load(self.fp)
Expand Down

0 comments on commit ccac9e1

Please sign in to comment.