From 7a12908db904cfbda9a43e5ea805d210d5c0652c Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Thu, 7 May 2020 03:27:39 -0700 Subject: [PATCH] Relocate example plugin --- misc/example_plugin.py | 53 +++++++++++++++++++++++++++++++++++++++++ src/ocrmypdf/example.py | 38 ----------------------------- 2 files changed, 53 insertions(+), 38 deletions(-) create mode 100644 misc/example_plugin.py delete mode 100644 src/ocrmypdf/example.py diff --git a/misc/example_plugin.py b/misc/example_plugin.py new file mode 100644 index 00000000..d6c93363 --- /dev/null +++ b/misc/example_plugin.py @@ -0,0 +1,53 @@ +# © 2020 James R Barlow: https://github.com/jbarlow83 +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import logging + +from PIL import Image + +from ocrmypdf import hookimpl + +log = logging.getLogger(__name__) + + +@hookimpl +def add_options(parser): + parser.add_argument('--grayscale-ocr', action='store_true') + + +@hookimpl +def prepare(options): + pass + + +@hookimpl +def validate(pdfinfo, options): + pass + + +@hookimpl +def filter_ocr_image(page, image): + if page.options.grayscale_ocr: + log.info("graying") + return image.convert('L') + return image + + +@hookimpl +def filter_page_image(page, image_filename): + output = image_filename.with_suffix('.jpg') + with Image.open(image_filename) as im: + im.save(output) + return output diff --git a/src/ocrmypdf/example.py b/src/ocrmypdf/example.py deleted file mode 100644 index 926831c3..00000000 --- a/src/ocrmypdf/example.py +++ /dev/null @@ -1,38 +0,0 @@ -import logging - -from PIL import Image - -from ocrmypdf import hookimpl - -log = logging.getLogger(__name__) - - -@hookimpl -def add_options(parser): - parser.add_argument('--grayscale-ocr', action='store_true') - - -@hookimpl -def prepare(options): - pass - - -@hookimpl -def validate(pdfinfo, options): - pass - - -@hookimpl -def filter_ocr_image(page, image): - if page.options.grayscale_ocr: - log.info("graying") - return image.convert('L') - return image - - -@hookimpl -def filter_page_image(page, image_filename): - output = image_filename.with_suffix('.jpg') - with Image.open(image_filename) as im: - im.save(output) - return output