{"record":{"id":"dbd633f337fcef55","repo":"ocrmypdf/OCRmyPDF","slug":"input-file-is-an-image-but-has-no-resolution-dpi","errorCode":null,"errorMessage":"Input file is an image, but has no resolution (DPI) in its metadata.  Estimate the resolution at which the image was scanned and specify it using --image-dpi.","messagePattern":"Input file is an image, but has no resolution \\(DPI\\) in its metadata\\.  Estimate the resolution at which the image was scanned and specify it using --image-dpi\\.","errorType":"error_code","errorClass":"DpiError","httpStatus":null,"severity":"error","filePath":"src/ocrmypdf/_pipeline.py","lineNumber":117,"sourceCode":"            log.error(\"Input file is a file: %s\", input_file)\n        if input_file.stat().st_size == 0:\n            log.error(\"Input file is empty: %s\", input_file)\n        raise UnsupportedImageFormatError() from e\n\n    with im:\n        log.info(\"Input file is an image\")\n        if 'dpi' in im.info:\n            if im.info['dpi'] <= (96, 96) and not options.image_dpi:\n                log.info(\"Image size: (%d, %d)\", *im.size)\n                log.info(\"Image resolution: (%d, %d)\", *im.info['dpi'])\n                raise DpiError(\n                    \"Input file is an image, but the resolution (DPI) is \"\n                    \"not credible.  Estimate the resolution at which the \"\n                    \"image was scanned and specify it using --image-dpi.\"\n                )\n        elif not options.image_dpi:\n            log.info(\"Image size: (%d, %d)\", *im.size)\n            raise DpiError(\n                \"Input file is an image, but has no resolution (DPI) \"\n                \"in its metadata.  Estimate the resolution at which \"\n                \"image was scanned and specify it using --image-dpi.\"\n            )\n\n        if im.mode in ('RGBA', 'LA'):\n            raise UnsupportedImageFormatError(\n                \"The input image has an alpha channel. Remove the alpha channel first.\"\n            )\n\n        if 'iccprofile' not in im.info:\n            if im.mode == 'RGB':\n                log.info(\"Input image has no ICC profile, assuming sRGB\")\n            elif im.mode == 'CMYK':\n                raise UnsupportedImageFormatError(\n                    \"Input CMYK image has no ICC profile, not usable\"\n                )\n","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/ocrmypdf/OCRmyPDF/blob/5074a0b0e109362422b768fd271ed84bf717c4ec/src/ocrmypdf/_pipeline.py#L99-L135","documentation":"Raised when an image input file has no DPI metadata at all. Without resolution info ocrmypdf cannot compute page dimensions for the output PDF, so it requires --image-dpi.","triggerScenarios":"Passing an image with no 'dpi' key in its Pillow info dict and no --image-dpi option; raised in triage_image_file.","commonSituations":"PNG files (which often omit DPI), downloaded images, images processed by tools that strip metadata.","solutions":["Pass --image-dpi with the estimated scan resolution (commonly 300)","Embed DPI metadata in the image before running (Pillow: img.save(..., dpi=(300,300)))","Convert to PDF yourself with img2pdf specifying the layout"],"exampleFix":"# before\nocrmypdf photo.png out.pdf\n# after\nocrmypdf --image-dpi 300 photo.png out.pdf","handlingStrategy":"validation","validationCode":"from PIL import Image\nwith Image.open(src) as im:\n    if 'dpi' not in im.info and not image_dpi:\n        image_dpi = 300","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize image inputs (embed DPI) before handing them to ocrmypdf"],"tags":["ocr","ocrmypdf","image-metadata","dpi"],"backgroundTag":"missing-image-metadata","analyzedSha":"5074a0b0e109362422b768fd271ed84bf717c4ec","analyzedAt":"2026-08-27T11:57:38.523Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}