Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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