From 9836b976d3e815c6b4f73a3c03afa7fb822dfa3c Mon Sep 17 00:00:00 2001 From: Johannes 'josch' Schauer Date: Wed, 18 Oct 2017 10:34:59 +0200 Subject: [PATCH] src/img2pdf.py: handle Pillow returning a DPI of zero (closes: #36) --- src/img2pdf.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/img2pdf.py b/src/img2pdf.py index 4cac4ed..ac23eda 100755 --- a/src/img2pdf.py +++ b/src/img2pdf.py @@ -600,6 +600,13 @@ def get_imgmetadata(imgdata, imgformat, default_dpi, colorspace, rawdata=None): ndpi = (int(round(ndpi[0])), int(round(ndpi[1]))) ics = imgdata.mode + # Since commit 07a96209597c5e8dfe785c757d7051ce67a980fb or release 4.1.0 + # Pillow retrieves the DPI from EXIF if it cannot find the DPI in the JPEG + # header. In that case it can happen that the horizontal and vertical DPI + # are set to zero. + if ndpi == (0, 0): + ndpi = (default_dpi, default_dpi) + logging.debug("input dpi = %d x %d", *ndpi) if colorspace: