Repository navigation
fix(image): treat zero DPI metadata as missing - #4915
Conversation
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>
|
✅ DCO Check Passed Thanks @wak327, 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 Adds 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 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.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ImageDocumentBackendreads 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
pHYschunk stores zero pixels per unit reads back from Pillow asdpi=(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_documentcovers that case, and I kept it unchanged. The docs sentence on image DPI indocs/usage/advanced_options.mdnow lists(0, 0).Issue resolved by this Pull Request:
Resolves #4779
Checklist:
Review evidence:
Converting a 400x120 PNG saved with Pillow
dpi=(0, 0):maindpi=(0, 0)FAILURE: Could not load imageSUCCESS, page 400x120 ptdpi=(0, 300)FAILUREFAILURE(unchanged)test_zero_dpi_defaults_to_72_dpi(new) fails onmainand passes with the fix.uv run pytest tests/test_backend_image_native.py: 31 passed.make validate: passed.