From b726afbb5ad07144df381cdd859b4c8f7010c472 Mon Sep 17 00:00:00 2001 From: "Ryan C. Thompson" <rct@thompsonclan.org> Date: Wed, 5 Nov 2014 23:47:42 -0800 Subject: [PATCH] Convert unrecognized colorspaces to RGB Instead of crashing on an unrecognized colorspace, we now do imgdata.convert('RGB'). --- src/img2pdf.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/img2pdf.py b/src/img2pdf.py index 16745c7..24e92a3 100755 --- a/src/img2pdf.py +++ b/src/img2pdf.py @@ -265,8 +265,15 @@ def convert(images, dpi, x, y, title=None, author=None, creator=None, producer=N else: # because we do not support /CCITTFaxDecode if color == '1': + debug_out("Converting colorspace 1 to L", verbose) imgdata = imgdata.convert('L') color = 'L' + elif color in ("RGB", "L"): + debug_out("Colorspace is OK: %s"%color, verbose) + else: + debug_out("Converting colorspace %s to RGB"%color, verbose) + imgdata = imgdata.convert('RGB') + color = imgdata.mode imgdata = zlib.compress(imgdata.tostring()) # pdf units = 1/72 inch