Skip to content

Commit

Permalink
Merge pull request #4471 from radarhere/exif_imagemagick
Browse files Browse the repository at this point in the history
Added reading of earlier ImageMagick PNG EXIF data
  • Loading branch information
hugovk authored Mar 26, 2020
2 parents b29ef9a + d4b627b commit 3970db0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Binary file added Tests/images/exif_imagemagick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,15 @@ def test_textual_chunks_after_idat(self):
with Image.open("Tests/images/hopper_idat_after_image_end.png") as im:
assert im.text == {"TXT": "VALUE", "ZIP": "VALUE"}

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

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 3970db0

Please sign in to comment.