Skip to content

Commit

Permalink
Added reading of earlier ImageMagick EXIF data
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Mar 13, 2020
1 parent ca00126 commit 747068c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Binary file added Tests/images/exif_imagemagick.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,13 @@ def test_textual_chunks_after_idat(self):
assert im.text == {"TXT": "VALUE", "ZIP": "VALUE"}

def test_exif(self):
with Image.open("Tests/images/exif.png") as im:
exif = im._getexif()
assert exif[274] == 1
for file in (
"Tests/images/exif.png", # With an EXIF chunk
"Tests/images/exif_imagemagick.png", # With an ImageMagick zTXt chunk
):
with Image.open(file) as im:
exif = im._getexif()
assert exif[274] == 1

def test_exif_save(self, tmp_path):
with Image.open("Tests/images/exif.png") as im:
Expand Down
14 changes: 12 additions & 2 deletions src/PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,24 @@ def load_end(self):
def _getexif(self):
if "exif" not in self.info:
self.load()
if "exif" not in self.info:
if "exif" not in self.info and "Raw profile type exif" not in self.info:
return None
return dict(self.getexif())

def getexif(self):
if "exif" not in self.info:
self.load()
return ImageFile.ImageFile.getexif(self)

if self._exif is None:
self._exif = Image.Exif()

exif_info = self.info.get("exif")
if exif_info is None and "Raw profile type exif" in self.info:
exif_info = bytes.fromhex(
"".join(self.info["Raw profile type exif"].split("\n")[3:])
)
self._exif.load(exif_info)
return self._exif


# --------------------------------------------------------------------
Expand Down

0 comments on commit 747068c

Please sign in to comment.