1
0
Fork 0
forked from josch/plakativ

print proper error message when trying to read raster images with alpha channel and suppress img2pdf messages

This commit is contained in:
Johannes 'josch' Schauer 2020-09-26 19:18:32 +02:00
parent 8bab9a8bc6
commit 34213ae2a5
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -21,6 +21,7 @@ import os.path
import platform import platform
from enum import Enum from enum import Enum
from io import BytesIO from io import BytesIO
import logging
have_img2pdf = True have_img2pdf = True
try: try:
@ -1955,6 +1956,9 @@ def compute_layout(
# into a PDF container # into a PDF container
data = None data = None
try: try:
# FIXME: img2pdf should not use the root logger so that instead we
# can run logging.getLogger('img2pdf').setLevel(logging.CRITICAL)
logging.getLogger().setLevel(logging.CRITICAL)
data = img2pdf.convert(infile) data = img2pdf.convert(infile)
except img2pdf.AlphaChannelError: except img2pdf.AlphaChannelError:
if remove_alpha: if remove_alpha:
@ -1969,7 +1973,14 @@ def compute_layout(
output.seek(0) output.seek(0)
data = img2pdf.convert(output) data = img2pdf.convert(output)
else: else:
raise print(
"""
Plakativ is lossless by default. To automatically remove the alpha channel from
the input and place the image on a white background, use the --remove-alpha
option""",
file=sys.stderr,
)
exit(1)
except img2pdf.ImageOpenError: except img2pdf.ImageOpenError:
# img2pdf cannot handle this # img2pdf cannot handle this
pass pass