Repository navigation
fix(html): use 72 DPI fallback for HTML and MHTML images with 0 DPI metadata - #5165
Conversation
…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 <65058495+shashank11yadav@users.noreply.github.com>
|
✅ DCO Check Passed Thanks @shashank11yadav, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
AI triage (advisory)Checked commit 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: CI safety: no concern found. A maintainer must still approve CI. 1 related pull request(s) in the same code
The |
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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 resultingImageRefhaddpi=0. Both read sites now fall back to 72 DPI, as the image backend does for(0, 0)since #4915.Behavior change:
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.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_dpitests/test_backend_mhtml.py::test_embedded_image_with_zero_dpi_defaults_to_72_dpiIssue resolved by this Pull Request:
Resolves #5163
Checklist:
Review evidence:
Before: on upstream/main, a PNG with pHYs zero (
dpi=(0, 0)) loads withImageRef.dpi == 0. Both new tests fail withassert 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.test_fetch_refuses_non_public_hostandtest_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.