mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 10:46:16 +03:00
Added reading of earlier ImageMagick EXIF data
This commit is contained in:
parent
ca00126e2b
commit
ca5a81ef27
BIN
Tests/images/exif_imagemagick.png
Normal file
BIN
Tests/images/exif_imagemagick.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 175 KiB |
|
@ -593,9 +593,13 @@ class TestFilePng:
|
||||||
assert im.text == {"TXT": "VALUE", "ZIP": "VALUE"}
|
assert im.text == {"TXT": "VALUE", "ZIP": "VALUE"}
|
||||||
|
|
||||||
def test_exif(self):
|
def test_exif(self):
|
||||||
with Image.open("Tests/images/exif.png") as im:
|
for test_file in (
|
||||||
exif = im._getexif()
|
"Tests/images/exif.png", # With an EXIF chunk
|
||||||
assert exif[274] == 1
|
"Tests/images/exif_imagemagick.png", # With an ImageMagick zTXt chunk
|
||||||
|
):
|
||||||
|
with Image.open(test_file) as im:
|
||||||
|
exif = im._getexif()
|
||||||
|
assert exif[274] == 1
|
||||||
|
|
||||||
def test_exif_save(self, tmp_path):
|
def test_exif_save(self, tmp_path):
|
||||||
with Image.open("Tests/images/exif.png") as im:
|
with Image.open("Tests/images/exif.png") as im:
|
||||||
|
|
|
@ -694,14 +694,24 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
def _getexif(self):
|
def _getexif(self):
|
||||||
if "exif" not in self.info:
|
if "exif" not in self.info:
|
||||||
self.load()
|
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 None
|
||||||
return dict(self.getexif())
|
return dict(self.getexif())
|
||||||
|
|
||||||
def getexif(self):
|
def getexif(self):
|
||||||
if "exif" not in self.info:
|
if "exif" not in self.info:
|
||||||
self.load()
|
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
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user