mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-03 19:45:56 +03:00
Merge pull request #2632 from wiredfool/issue_2628
Fix JPEG DPI when EXIF is invalid
This commit is contained in:
commit
90886a4e59
|
@ -119,8 +119,8 @@ def APP(self, marker):
|
||||||
|
|
||||||
# If DPI isn't in JPEG header, fetch from EXIF
|
# If DPI isn't in JPEG header, fetch from EXIF
|
||||||
if "dpi" not in self.info and "exif" in self.info:
|
if "dpi" not in self.info and "exif" in self.info:
|
||||||
exif = self._getexif()
|
|
||||||
try:
|
try:
|
||||||
|
exif = self._getexif()
|
||||||
resolution_unit = exif[0x0128]
|
resolution_unit = exif[0x0128]
|
||||||
x_resolution = exif[0x011A]
|
x_resolution = exif[0x011A]
|
||||||
try:
|
try:
|
||||||
|
@ -131,7 +131,9 @@ def APP(self, marker):
|
||||||
# 1 dpcm = 2.54 dpi
|
# 1 dpcm = 2.54 dpi
|
||||||
dpi *= 2.54
|
dpi *= 2.54
|
||||||
self.info["dpi"] = dpi, dpi
|
self.info["dpi"] = dpi, dpi
|
||||||
except KeyError:
|
except (KeyError, SyntaxError):
|
||||||
|
# SyntaxError for invalid/unreadable exif
|
||||||
|
# KeyError for dpi not included
|
||||||
self.info["dpi"] = 72, 72
|
self.info["dpi"] = 72, 72
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
Tests/images/invalid-exif.jpg
Normal file
BIN
Tests/images/invalid-exif.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -546,6 +546,15 @@ class TestFileJpeg(PillowTestCase):
|
||||||
# http://www.exiv2.org/tags.html
|
# http://www.exiv2.org/tags.html
|
||||||
self.assertEqual(im.info.get("dpi"), (72, 72))
|
self.assertEqual(im.info.get("dpi"), (72, 72))
|
||||||
|
|
||||||
|
def test_invalid_exif(self):
|
||||||
|
# This is no-dpi-in-exif with the tiff header of the exif block
|
||||||
|
# hexedited from MM * to FF FF FF FF
|
||||||
|
im = Image.open("Tests/images/invalid-exif.jpg")
|
||||||
|
|
||||||
|
# This should return the default, and not a SyntaxError or
|
||||||
|
# OSError for unidentified image.
|
||||||
|
self.assertEqual(im.info.get("dpi"), (72, 72))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith('win32'), "Windows only")
|
@unittest.skipUnless(sys.platform.startswith('win32'), "Windows only")
|
||||||
class TestFileCloseW32(PillowTestCase):
|
class TestFileCloseW32(PillowTestCase):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user