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:
parent
8bab9a8bc6
commit
34213ae2a5
1 changed files with 12 additions and 1 deletions
13
plakativ.py
13
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
|
||||
|
|
Loading…
Reference in a new issue