From a2b969640a1c57794ecf39aa5ffe5462cc7f1d6c Mon Sep 17 00:00:00 2001 From: Johannes 'josch' Schauer Date: Mon, 20 Aug 2018 10:24:31 +0200 Subject: [PATCH] src/img2pdf.py: assign the default dpi to tiff images where PIL returned its default of (1,1) --- src/img2pdf.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/img2pdf.py b/src/img2pdf.py index 84b99c9..31ba08d 100755 --- a/src/img2pdf.py +++ b/src/img2pdf.py @@ -682,6 +682,12 @@ def get_imgmetadata(imgdata, imgformat, default_dpi, colorspace, rawdata=None): if ndpi == (0, 0): ndpi = (default_dpi, default_dpi) + # PIL defaults to a dpi of 1 if a TIFF image does not specify the dpi. + # In that case, we want to use a different default. + if ndpi == (1, 1) and imgformat == ImageFormat.TIFF: + ndpi = (imgdata.tag_v2.get(TiffImagePlugin.X_RESOLUTION, default_dpi), + imgdata.tag_v2.get(TiffImagePlugin.Y_RESOLUTION, default_dpi)) + logging.debug("input dpi = %d x %d", *ndpi) if colorspace: