From bc5d3824bd0c4893e8d37e3ccbd2cac255cee58e Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sun, 31 Jul 2016 02:09:30 -0700 Subject: [PATCH] Don't overload --oversample, use --image-dpi instead for images --- ocrmypdf/main.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ocrmypdf/main.py b/ocrmypdf/main.py index bbf9a4e6..1bc1e7b5 100755 --- a/ocrmypdf/main.py +++ b/ocrmypdf/main.py @@ -123,6 +123,9 @@ parser.add_argument( parser.add_argument( '-j', '--jobs', metavar='N', type=int, help="Use up to N CPU cores simultaneously (default: use all)") +parser.add_argument( + '--image-dpi', metavar='DPI', type=int, + help="for input image instead of PDF, use this DPI instead of file's") metadata = parser.add_argument_group( "Metadata options", @@ -399,20 +402,20 @@ def triage_image_file(input_file, output_file, log): log.info("Input file is an image") if 'dpi' in im.info: - if im.info['dpi'] <= (96, 96) and not options.oversample: + if im.info['dpi'] <= (96, 96) and not options.image_dpi: log.info("Image size: (%d, %d)" % im.size) log.info("Image resolution: (%d, %d)" % im.info['dpi']) log.error( "Input file is an image, but the resolution (DPI) is " "not credible. Estimate the resolution at which the " - "image was scanned and specify it using --oversample.") + "image was scanned and specify it using --image-dpi.") sys.exit(ExitCode.input_file) - elif not options.oversample: + elif not options.image_dpi: log.info("Image size: (%d, %d)" % im.size) log.error( "Input file is an image, but has no resolution (DPI) " "in its metadata. Estimate the resolution at which " - "image was scanned and specify it using --oversample.") + "image was scanned and specify it using --image-dpi.") sys.exit(ExitCode.input_file) finally: im.close() @@ -420,9 +423,9 @@ def triage_image_file(input_file, output_file, log): try: log.info("Image seems valid. Try converting to PDF...") layout_fun = img2pdf.default_layout_fun - if options.oversample: + if options.image_dpi: layout_fun = img2pdf.get_fixed_dpi_layout_fun( - (options.oversample, options.oversample)) + (options.image_dpi, options.image_dpi)) with open(output_file, 'wb') as outf: img2pdf.convert( input_file,