Corrected reading EXIF metadata without prefix

This commit is contained in:
Andrew Murray 2020-06-07 20:01:04 +10:00
parent 9df95e77c5
commit 0cc2e696cb
2 changed files with 12 additions and 1 deletions

View File

@ -30,6 +30,15 @@ def test_read_exif_metadata():
assert exif_data == expected_exif assert exif_data == expected_exif
def test_read_exif_metadata_without_prefix():
with Image.open("Tests/images/flower2.webp") as im:
# Assert prefix is not present
assert im.info["exif"][:6] != b"Exif\x00\x00"
exif = im.getexif()
assert exif[305] == "Adobe Photoshop CS6 (Macintosh)"
def test_write_exif_metadata(): def test_write_exif_metadata():
file_path = "Tests/images/flower.jpg" file_path = "Tests/images/flower.jpg"
test_buffer = BytesIO() test_buffer = BytesIO()

View File

@ -3289,7 +3289,9 @@ class Exif(MutableMapping):
if not data: if not data:
return return
self.fp = io.BytesIO(data[6:]) if data.startswith(b"Exif\x00\x00"):
data = data[6:]
self.fp = io.BytesIO(data)
self.head = self.fp.read(8) self.head = self.fp.read(8)
# process dictionary # process dictionary
from . import TiffImagePlugin from . import TiffImagePlugin