ocrmypdf/OCRmyPDF · error · DpiError

Input file is an image, but the resolution (DPI) is not cred

Error message

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 --image-dpi.

What it means

Raised by triage_image_file when a raw image input has DPI metadata that is <= (96, 96), which is almost certainly a default/guessed value rather than a real scan resolution. OCR quality depends on knowing the true DPI, so ocrmypdf refuses to guess.

Source

Thrown at src/ocrmypdf/_pipeline.py:110

        # Recover the original filename
        log.error(str(e).replace(str(input_file), str(options.input_file)))
        if not input_file.exists():
            log.error("Input file does not exist: %s", input_file)
        if input_file.is_dir():
            log.error("Input file is a directory: %s", input_file)
        if input_file.is_file():
            log.error("Input file is a file: %s", input_file)
        if input_file.stat().st_size == 0:
            log.error("Input file is empty: %s", input_file)
        raise UnsupportedImageFormatError() from e

    with im:
        log.info("Input file is an image")
        if 'dpi' in im.info:
            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'])
                raise DpiError(
                    "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 --image-dpi."
                )
        elif not options.image_dpi:
            log.info("Image size: (%d, %d)", *im.size)
            raise DpiError(
                "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 --image-dpi."
            )

        if im.mode in ('RGBA', 'LA'):
            raise UnsupportedImageFormatError(
                "The input image has an alpha channel. Remove the alpha channel first."
            )

        if 'iccprofile' not in im.info:

View on GitHub (pinned to 5074a0b0e1)

Solutions

  1. Determine the real scan resolution and pass --image-dpi (e.g. --image-dpi 300)
  2. Re-save the image with correct DPI metadata embedded
  3. Convert the image to PDF first with the correct DPI (e.g. via img2pdf)

Example fix

# before
ocrmypdf scan.jpg out.pdf
# after
ocrmypdf --image-dpi 300 scan.jpg out.pdf
Defensive patterns

Strategy: validation

Validate before calling

from PIL import Image
with Image.open(src) as im:
    dpi = im.info.get('dpi')
    if dpi and tuple(dpi) <= (96, 96) and not image_dpi:
        image_dpi = 300  # ask user or assume scan default

Prevention

When it happens

Trigger: Feeding a JPEG/PNG/TIFF image (not PDF) whose embedded dpi metadata is 96x96 or lower, without specifying --image-dpi; occurs during triage before PDF conversion.

Common situations: Images exported from phones/screenshots/web downloads that carry a default 96 DPI tag; scanned images whose metadata was stripped.

Related errors


AI-assisted analysis of ocrmypdf/OCRmyPDF@5074a0b0e1 (2026-08-27). Data as JSON: /api/errors/727b9bfaacfb10ce. Report an issue: GitHub.