From 77ee44fe63394ec7b294d300fce2f77afc504b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Sun, 18 Jul 2021 14:28:34 +0200 Subject: [PATCH] Add crop status image --- CHANGELOG.md | 1 + scan_to_paperless/process.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3a5a634..788a25aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,3 +5,4 @@ - Fix for scan @600 DPI - Introduce scan mode: `--double-sided` => `--mode=double`, `--no-adf` => `--mode=multi`, new mode `--mode=one` - Respect the deleted image during the preview +- Add crop status image diff --git a/scan_to_paperless/process.py b/scan_to_paperless/process.py index 30f36840..46770846 100755 --- a/scan_to_paperless/process.py +++ b/scan_to_paperless/process.py @@ -326,11 +326,21 @@ def crop(context: Context, margin_horizontal: int, margin_vertical: int) -> None """ Margin in px """ - contours = find_contours( - context.get_masked(), - context.get_px_value("min_box_size_crop", 3), - ) + image = context.get_masked() + contours = find_contours(image, context.get_px_value("min_box_size_crop", 3)) + if contours: + for contour in contours: + draw_rectangle(image, False, contour) + if context.root_folder is not None and context.image_name is not None: + save_image( + image, + context.root_folder, + "{}-crop".format(context.get_process_count()), + context.image_name, + True, + ) + x, y, width, height = get_contour_to_crop(contours, margin_horizontal, margin_vertical) context.crop(x, y, width, height)