From 43b0faa83071e298e51541ba64fcc8c51e99deb1 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Thu, 4 Feb 2016 18:48:22 -0800 Subject: [PATCH] Bug in tesseract_noop spoof: produced wrong page sizes Now checks input image to ensure the implied page size of its .hocr file matches the rest of the PDF. --- tests/spoof/tesseract_noop.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/spoof/tesseract_noop.py b/tests/spoof/tesseract_noop.py index ee7cadae..b0832dfe 100755 --- a/tests/spoof/tesseract_noop.py +++ b/tests/spoof/tesseract_noop.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import sys import img2pdf +from PIL import Image VERSION_STRING = '''tesseract 3.04.00 @@ -40,9 +41,12 @@ def main(): print('List of available languages (1):\neng', file=sys.stderr) sys.exit(0) elif sys.argv[-1] == 'hocr': + inputf = sys.argv[-3] output = sys.argv[-2] - with open(output + '.hocr', 'w', encoding='utf-8') as f: - f.write(HOCR_TEMPLATE.format('1000', '1000')) + with Image.open(inputf) as im, \ + open(output + '.hocr', 'w', encoding='utf-8') as f: + w, h = im.size + f.write(HOCR_TEMPLATE.format(str(w), str(h))) elif sys.argv[-1] == 'pdf': inputf = sys.argv[-3] output = sys.argv[-2]