mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Merge pull request #2449 from hugovk/dpi-from-exif
If DPI isn't in JPEG header, fetch from EXIF
This commit is contained in:
commit
977f319234
|
@ -117,6 +117,11 @@ def APP(self, marker):
|
|||
# plus constant header size
|
||||
self.info["mpoffset"] = self.fp.tell() - n + 4
|
||||
|
||||
# If DPI isn't in JPEG header, fetch from EXIF
|
||||
if "dpi" not in self.info and "exif" in self.info:
|
||||
x_resolution = self._getexif()[0x011A]
|
||||
self.info["dpi"] = x_resolution[0] / x_resolution[1]
|
||||
|
||||
|
||||
def COM(self, marker):
|
||||
#
|
||||
|
|
BIN
Tests/images/photoshop-200dpi.jpg
Normal file
BIN
Tests/images/photoshop-200dpi.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -500,6 +500,14 @@ class TestFileJpeg(PillowTestCase):
|
|||
reloaded.load()
|
||||
self.assertEqual(im.info['dpi'], reloaded.info['dpi'])
|
||||
|
||||
def test_dpi_from_exif(self):
|
||||
# Arrange
|
||||
# This Photoshop CC 2017 image has DPI in EXIF not metadata
|
||||
im = Image.open("Tests/images/photoshop-200dpi.jpg")
|
||||
|
||||
# Act / Assert
|
||||
self.assertEqual(im.info.get("dpi"), 200)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user