Fix KeyError: 'dpi' when using --threshold on image to PDF

Fixes #607
This commit is contained in:
James R. Barlow
2020-08-07 02:21:02 -07:00
parent 4fa28d7e74
commit 9b641055e1
2 changed files with 17 additions and 1 deletions
+3 -1
View File
@@ -530,7 +530,9 @@ def create_ocr_image(image: Path, page_context: PageContext):
if options.threshold:
pix = leptonica.Pix.frompil(im)
pix = pix.masked_threshold_on_background_norm()
im = pix.topil()
im_pix = pix.topil()
im_pix.info['dpi'] = im.info['dpi']
im = im_pix
del draw
+14
View File
@@ -877,3 +877,17 @@ def test_image_dpi_not_image(caplog, resources, outpdf):
'tests/plugins/tesseract_noop.py',
)
assert '--image-dpi is being ignored' in caplog.text
def test_image_dpi_threshold(resources, outpdf):
check_ocrmypdf(
resources / 'typewriter.png',
outpdf,
'--threshold',
'--image-dpi=170',
'--output-type=pdf',
'--optimize=0',
'--plugin',
'tests/plugins/tesseract_noop.py',
)
assert outpdf.exists()