From 34213ae2a512b63144382817d47191b7b66c28f3 Mon Sep 17 00:00:00 2001 From: Johannes 'josch' Schauer Date: Sat, 26 Sep 2020 19:18:32 +0200 Subject: [PATCH] print proper error message when trying to read raster images with alpha channel and suppress img2pdf messages --- plakativ.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plakativ.py b/plakativ.py index 1897a3c..dad1029 100755 --- a/plakativ.py +++ b/plakativ.py @@ -21,6 +21,7 @@ import os.path import platform from enum import Enum from io import BytesIO +import logging have_img2pdf = True try: @@ -1955,6 +1956,9 @@ def compute_layout( # into a PDF container data = None 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) except img2pdf.AlphaChannelError: if remove_alpha: @@ -1969,7 +1973,14 @@ def compute_layout( output.seek(0) data = img2pdf.convert(output) 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: # img2pdf cannot handle this pass