mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 09:26:16 +03:00
Merge pull request #4147 from beipang2/issue_4146
Use default DPI when exif provides invalid x_resolution
This commit is contained in:
commit
ee30fe1b39
BIN
Tests/images/invalid-exif-without-x-resolution.jpg
Normal file
BIN
Tests/images/invalid-exif-without-x-resolution.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
|
@ -638,6 +638,14 @@ class TestFileJpeg(PillowTestCase):
|
|||
# OSError for unidentified image.
|
||||
self.assertEqual(im.info.get("dpi"), (72, 72))
|
||||
|
||||
def test_invalid_exif_x_resolution(self):
|
||||
# When no x or y resolution is defined in EXIF
|
||||
im = Image.open("Tests/images/invalid-exif-without-x-resolution.jpg")
|
||||
|
||||
# This should return the default, and not a ValueError or
|
||||
# OSError for an unidentified image.
|
||||
self.assertEqual(im.info.get("dpi"), (72, 72))
|
||||
|
||||
def test_ifd_offset_exif(self):
|
||||
# Arrange
|
||||
# This image has been manually hexedited to have an IFD offset of 10,
|
||||
|
|
|
@ -166,10 +166,11 @@ def APP(self, marker):
|
|||
# 1 dpcm = 2.54 dpi
|
||||
dpi *= 2.54
|
||||
self.info["dpi"] = int(dpi + 0.5), int(dpi + 0.5)
|
||||
except (KeyError, SyntaxError, ZeroDivisionError):
|
||||
except (KeyError, SyntaxError, ValueError, ZeroDivisionError):
|
||||
# SyntaxError for invalid/unreadable EXIF
|
||||
# KeyError for dpi not included
|
||||
# ZeroDivisionError for invalid dpi rational value
|
||||
# ValueError for x_resolution[0] being an invalid float
|
||||
self.info["dpi"] = 72, 72
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user