mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-14 11:26:27 +03:00
Merge pull request #2484 from hugovk/exif-resolution-as-int
Fix for file with DPI in EXIF but not metadata, and XResolution is an int rather than tuple
This commit is contained in:
commit
17f799ed16
|
@ -123,7 +123,10 @@ def APP(self, marker):
|
||||||
try:
|
try:
|
||||||
resolution_unit = exif[0x0128]
|
resolution_unit = exif[0x0128]
|
||||||
x_resolution = exif[0x011A]
|
x_resolution = exif[0x011A]
|
||||||
dpi = x_resolution[0] / x_resolution[1]
|
try:
|
||||||
|
dpi = x_resolution[0] / x_resolution[1]
|
||||||
|
except TypeError:
|
||||||
|
dpi = x_resolution
|
||||||
if resolution_unit == 3: # cm
|
if resolution_unit == 3: # cm
|
||||||
# 1 dpcm = 2.54 dpi
|
# 1 dpcm = 2.54 dpi
|
||||||
dpi *= 2.54
|
dpi *= 2.54
|
||||||
|
|
BIN
Tests/images/exif-72dpi-int.jpg
Normal file
BIN
Tests/images/exif-72dpi-int.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 69 KiB |
|
@ -501,14 +501,24 @@ class TestFileJpeg(PillowTestCase):
|
||||||
reloaded.load()
|
reloaded.load()
|
||||||
self.assertEqual(im.info['dpi'], reloaded.info['dpi'])
|
self.assertEqual(im.info['dpi'], reloaded.info['dpi'])
|
||||||
|
|
||||||
def test_dpi_from_exif(self):
|
def test_dpi_tuple_from_exif(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# This Photoshop CC 2017 image has DPI in EXIF not metadata
|
# This Photoshop CC 2017 image has DPI in EXIF not metadata
|
||||||
|
# EXIF XResolution is (2000000, 10000)
|
||||||
im = Image.open("Tests/images/photoshop-200dpi.jpg")
|
im = Image.open("Tests/images/photoshop-200dpi.jpg")
|
||||||
|
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
self.assertEqual(im.info.get("dpi"), (200, 200))
|
self.assertEqual(im.info.get("dpi"), (200, 200))
|
||||||
|
|
||||||
|
def test_dpi_int_from_exif(self):
|
||||||
|
# Arrange
|
||||||
|
# This image has DPI in EXIF not metadata
|
||||||
|
# EXIF XResolution is 72
|
||||||
|
im = Image.open("Tests/images/exif-72dpi-int.jpg")
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
self.assertEqual(im.info.get("dpi"), (72, 72))
|
||||||
|
|
||||||
def test_dpi_from_dpcm_exif(self):
|
def test_dpi_from_dpcm_exif(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# This is photoshop-200dpi.jpg with EXIF resolution unit set to cm:
|
# This is photoshop-200dpi.jpg with EXIF resolution unit set to cm:
|
||||||
|
@ -535,7 +545,7 @@ class TestFileCloseW32(PillowTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
if "jpeg_encoder" not in codecs or "jpeg_decoder" not in codecs:
|
if "jpeg_encoder" not in codecs or "jpeg_decoder" not in codecs:
|
||||||
self.skipTest("jpeg support not available")
|
self.skipTest("jpeg support not available")
|
||||||
|
|
||||||
def test_fd_leak(self):
|
def test_fd_leak(self):
|
||||||
tmpfile = self.tempfile("temp.jpg")
|
tmpfile = self.tempfile("temp.jpg")
|
||||||
import os
|
import os
|
||||||
|
@ -549,8 +559,9 @@ class TestFileCloseW32(PillowTestCase):
|
||||||
self.assertRaises(Exception, lambda: os.remove(tmpfile))
|
self.assertRaises(Exception, lambda: os.remove(tmpfile))
|
||||||
im.load()
|
im.load()
|
||||||
self.assertTrue(fp.closed)
|
self.assertTrue(fp.closed)
|
||||||
# this should not fail, as load should have closed the file.
|
# this should not fail, as load should have closed the file.
|
||||||
os.remove(tmpfile)
|
os.remove(tmpfile)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user