From 7a8161162f599dea3205a90b55505a3d88610859 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Tue, 18 Jul 2017 00:54:11 -0700 Subject: [PATCH] fix for https://github.com/python-pillow/Pillow/issues/2628#issuecomment-315962612 --- PIL/JpegImagePlugin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index ee29a8add..47fb0a6df 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -119,8 +119,8 @@ def APP(self, marker): # If DPI isn't in JPEG header, fetch from EXIF if "dpi" not in self.info and "exif" in self.info: - exif = self._getexif() try: + exif = self._getexif() resolution_unit = exif[0x0128] x_resolution = exif[0x011A] try: @@ -131,7 +131,9 @@ def APP(self, marker): # 1 dpcm = 2.54 dpi dpi *= 2.54 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