Disallow input images with alpha channel as it cannot be preserved in the PDF and would thus make img2pdf not lossless

This commit is contained in:
Johannes 'josch' Schauer 2018-03-24 18:55:14 +01:00
parent 1d9a25dfd2
commit 7244d2c6ed
Signed by: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -637,6 +637,9 @@ def get_imgmetadata(imgdata, imgformat, default_dpi, colorspace, rawdata=None):
ndpi = (int(round(ndpi[0])), int(round(ndpi[1]))) ndpi = (int(round(ndpi[0])), int(round(ndpi[1])))
ics = imgdata.mode 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 # Since commit 07a96209597c5e8dfe785c757d7051ce67a980fb or release 4.1.0
# Pillow retrieves the DPI from EXIF if it cannot find the DPI in the JPEG # 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 # header. In that case it can happen that the horizontal and vertical DPI