Skip to content

fix(html): use 72 DPI fallback for HTML and MHTML images with 0 DPI metadata - #5165

Merged
PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
shashank11yadav:fix/5163-html-zero-dpi-fallback
Nov 5, 2026
Merged

PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
shashank11yadav:fix/5163-html-zero-dpi-fallback

Conversation

@shashank11yadav

Copy link
Copy Markdown
Contributor

Image resources with 0 DPI metadata now get the 72 DPI default in the HTML and MHTML backends.

A PNG whose pHYs chunk has zero pixels per unit is read by Pillow as dpi=(0, 0). The HTML image loader and the MHTML embedded-image path both copied that value, so the resulting ImageRef had dpi=0. Both read sites now fall back to 72 DPI, as the image backend does for (0, 0) since #4915.

Behavior change:

  • Images with non-zero DPI metadata are unchanged.

Not changed here:

  • (1, 1) DPI metadata is still read as-is. The image backend treats (1, 1) as missing too, so this could be a follow-up.
  • The LaTeX backend (docling/backend/latex/handlers/macros.py) reads the same zero DPI value. Left for a follow-up.

Tests:

  • tests/test_image_resource_loader.py::test_zero_dpi_image_defaults_to_72_dpi
  • tests/test_backend_mhtml.py::test_embedded_image_with_zero_dpi_defaults_to_72_dpi

Issue resolved by this Pull Request:
Resolves #5163

Checklist:

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

Review evidence:

Before: on upstream/main, a PNG with pHYs zero (dpi=(0, 0)) loads with ImageRef.dpi == 0. Both new tests fail with assert 0 == 72.

After: both new tests pass. Commands run:

  • uv run pytest -v tests/test_image_resource_loader.py tests/test_backend_mhtml.py tests/test_backend_html.py -k "not test_fetch_refuses_non_public_host and not test_fetch_refuses_redirect_to_non_public_host": 184 passed, 2 skipped, 4 deselected.
  • Deselected test_fetch_refuses_non_public_host and test_fetch_refuses_redirect_to_non_public_host (4 items): two of them fail in my local environment on upstream main too (DID NOT RAISE ValueError).
  • uv run ruff check --config=pyproject.toml docling tests docs/examples scripts/benchmarking scripts/tools: passed.
  • uv run ruff format --check --config=pyproject.toml docling tests docs/examples scripts/benchmarking scripts/tools: passed.
  • uv run --no-sync ty check: passed.

Not run: the full test suite and make check.

…etadata

A PNG whose pHYs chunk has zero pixels per unit is read by Pillow as
dpi=(0.0, 0.0). The HTML image loader and the MHTML embedded-image path
copied that value, so the resulting ImageRef had dpi=0. Fall back to 72
DPI at both read sites, as the image backend already does.

Add a regression test for each path.

Resolves docling-project#5163

Signed-off-by: Shashank Yadav <[email protected]>
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

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

@mergify

mergify Bot commented Nov 3, 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 html issue related to html backend labels Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

AI triage (advisory)

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

The HTML backend and the shared image resource loader now use 72 DPI when an image has 0 DPI metadata. The PR adds one test for the loader and one test for the MHTML backend.

Topic labels added: bug, html.

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

1 related pull request(s) in the same code
PR State Signal Assessment
#4915 merged referenced as #4915 related: PR 4915 made the same zero-DPI fix in the image backend and is merged. This PR applies the fix to the HTML, MHTML, and image resource loader code, which PR 4915 did not change.

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 added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Nov 3, 2026

@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 382c56f42e. It read the code and did not run it.

I found no defects. Both read sites, docling/backend/html_backend.py:5396 and docling/backend/utils/image_resource_loader.py:374, now map a zero DPI value to 72. Non-zero DPI values and the missing-DPI default stay the same. The two new tests give zero DPI through a PNG pHYs chunk, one on the HTML path and one on the MHTML path, and they assert 72.

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

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@PeterStaar-IBM
PeterStaar-IBM merged commit e03c1aa into docling-project:main Nov 5, 2026
34 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 html issue related to html backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTML/MHTML: images with 0 DPI metadata get dpi=0 instead of the 72 DPI fallback (follow-up to #4915)

2 participants