From 7244d2c6edcbc7bf9cf1110420ce2b8e8ffa6b01 Mon Sep 17 00:00:00 2001 From: Johannes 'josch' Schauer Date: Sat, 24 Mar 2018 18:55:14 +0100 Subject: [PATCH] Disallow input images with alpha channel as it cannot be preserved in the PDF and would thus make img2pdf not lossless --- src/img2pdf.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/img2pdf.py b/src/img2pdf.py index e6537f2..95d5bbb 100755 --- a/src/img2pdf.py +++ b/src/img2pdf.py @@ -637,6 +637,9 @@ def get_imgmetadata(imgdata, imgformat, default_dpi, colorspace, rawdata=None): ndpi = (int(round(ndpi[0])), int(round(ndpi[1]))) ics = imgdata.mode + if ics in ["LA", "PA", "RGBA"]: + raise Exception("Image contains transparency which cannot be retained in PDF") + # 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