Skip to content

fix(image): treat zero DPI metadata as missing - #4915

Merged
cau-git merged 1 commit into
docling-project:mainfrom
wak327:fix/image-zero-dpi-defaults
Oct 28, 2026
Merged

cau-git merged 1 commit into
docling-project:mainfrom
wak327:fix/image-zero-dpi-defaults

Conversation

@wak327

@wak327 wak327 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

ImageDocumentBackend reads the page size from the embedded DPI metadata (#4012). Missing DPI and the (1, 1) placeholder fall back to 72 DPI, and any other non-positive value is rejected.

A PNG whose pHYs chunk stores zero pixels per unit reads back from Pillow as dpi=(0.0, 0.0). That value is rejected, so the whole image fails to load with "Could not load image for document". As the question in #4779 suggests, (0, 0) carries no resolution, the same as (1, 1). It now also falls back to 72 DPI.

A DPI with only one zero axis, such as (0, 300), is still rejected. test_invalid_explicit_dpi_rejects_document covers that case, and I kept it unchanged. The docs sentence on image DPI in docs/usage/advanced_options.md now lists (0, 0).

Issue resolved by this Pull Request:
Resolves #4779

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Review evidence:

Converting a 400x120 PNG saved with Pillow dpi=(0, 0):

main this PR
dpi=(0, 0) FAILURE: Could not load image SUCCESS, page 400x120 pt
dpi=(0, 300) FAILURE FAILURE (unchanged)
  • test_zero_dpi_defaults_to_72_dpi (new) fails on main and passes with the fix.
  • uv run pytest tests/test_backend_image_native.py: 31 passed.
  • make validate: passed.

A PNG whose pHYs chunk stores zero pixels per unit reads back from
Pillow as dpi=(0.0, 0.0). `_validate_dpi` rejects a non-positive value,
so the whole image failed to load ("Could not load image").

Like the (1, 1) placeholder, (0, 0) carries no resolution, so fall back
to 72 DPI for it. A DPI with only one zero axis, such as (0, 300), is
still rejected as before.

Signed-off-by: Waleed Khalid <wak327@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @wak327, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working labels Oct 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit b2e0c58cb9. The analysis read the diff only. It did not run code from this pull request.

Adds (0, 0) to the no-resolution DPI fallback set in _get_frame_dpi so that a PNG whose pHYs chunk stores zero pixels per unit loads successfully instead of raising a DocumentLoadError. A regression test and a doc update are included.

Topic labels added: bug.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#4012 merged referenced as #4012 related: PR #4012 (merged) introduced the _validate_dpi/_get_frame_dpi system and the (1, 1) fallback that this PR extends; the two PRs fix different gaps and cannot be substituted for each other.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the full diff at b2e0c58cb9. It read the code and did not run it.

I found no merge-deciding defect. In docling/backend/image_backend.py, _get_frame_dpi now maps (0, 0) to 72 DPI. Pillow's PNG reader (chunk_pHYs) gives (0.0, 0.0) for zero pixels per unit, and 0.0 == 0 makes the tuple match. The new test in tests/test_backend_image_native.py covers this case. The existing (0, 300) rejection test is unchanged.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 20, 2026
@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cau-git
cau-git merged commit 2a55ea6 into docling-project:main Oct 28, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Question about handling images with zero DPI metadata

2 participants