From 3e65f172182a2946c945fa1738f659316c6d2300 Mon Sep 17 00:00:00 2001 From: Anton Akhmerov <anton.akhmerov@gmail.com> Date: Sat, 21 Apr 2018 17:52:16 +0200 Subject: [PATCH] allow using monochromatic scans --- zesje/helpers/pdf_helper.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/zesje/helpers/pdf_helper.py b/zesje/helpers/pdf_helper.py index 08b7d5153..0ce351034 100644 --- a/zesje/helpers/pdf_helper.py +++ b/zesje/helpers/pdf_helper.py @@ -258,10 +258,12 @@ def guess_dpi(image_array): def rotate_and_shift(image_data, extracted_qr, qr_coords): """Roll the image such that QR occupies coords specified by the template.""" page, position = extracted_qr.page, extracted_qr.coords - image = np.asarray(image_data) + image = np.array(image_data) if image.shape[0] < image.shape[1]: - image = np.transpose(image, (1, 0, 2)) + image = np.copy(np.transpose( + image, ((1, 0) if len(image.shape) == 2 else (1, 0, 2)) + )) dpi = guess_dpi(image) h, w, *_ = image.shape @@ -280,6 +282,10 @@ def rotate_and_shift(image_data, extracted_qr, qr_coords): shifted_image = np.roll(image, shift[0], axis=0) shifted_image = np.roll(shifted_image, shift[1], axis=1) + # Workaround of https://github.com/python-pillow/Pillow/issues/3109 + if shifted_image.dtype == bool: + shifted_image = shifted_image * np.uint8(255) + return Image.fromarray(shifted_image) -- GitLab