Repository navigation
fix(pptx): extract the picture of a picture-filled shape - #4989
PeterStaar-IBM merged 4 commits into
Conversation
A shape filled with a picture (p:sp with a:blipFill in p:spPr) is read by python-pptx as an Autoshape, so only its text was handled and the image was dropped. Extract the embedded fill image as a picture item, like a p:pic, and keep the shape's text as well. Linked fills are left out. Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
|
✅ DCO Check Passed Thanks @sarankumar1325, 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 This pull request extracts embedded images from PowerPoint shapes that have a picture fill. CI safety: no concern found. A maintainer must still approve CI. The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at 02ea328f73. It read the code and did not run it.
The changes correctly extract embedded picture fills from PowerPoint autoshapes while preserving associated shape text and ignoring external links. I checked relationship resolution via shape.part.related_part, exception handling for malformed fills, provenance generation, and test coverage across embedded and linked fills.
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! |
tests/test_backend_pptx.py went over the 1500-line limit of the max-lines hook. Also cover a fill whose relationship is missing. Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the changes since 02ea328f73 at 00ef272e72. It read the code and did not run it.
The incremental change moves the picture-fill tests into tests/test_backend_pptx_picture_fill.py and adds a test case for missing relationship targets. I checked relationship handling, warning assertions, and shape text extraction across the test cases.
A maintainer makes the merge decision. This review never approves the pull request.
Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
uommou
left a comment
There was a problem hiding this comment.
Thanks for picking this up so quickly! I opened #4988, so I checked the change against the case in the issue.
What I ran on 41a2daff:
pytest tests/test_backend_pptx.py tests/test_backend_pptx_*.py: 86 passed.- The new test file against the base
mspowerpoint_backend.py(5de229e5): 6 of 7 fail, so the tests catch the original defect.test_pptx_linked_picture_fill_is_ignoredpasses on the base too, as expected. - The reproducer from the issue: base gives 0 pictures; head gives 1
PictureItembefore the shape'sTextItem, with bbox(914400, 914400, 2743200, 1828800), which matches the shape.
Not run: make check (CI lint-and-type passes on this head).
I left one small suggestion inline.
Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
|
Thanks for the review! Good call on linked-only fills. I've added a UserWarning when a picture fill has no embedded image, plus tests for it, in the latest commit. |
A shape filled with a picture (Format Shape > Fill > Picture or texture fill) is a
p:spwith ana:blipFillin itsp:spPr. python-pptx reads it as anAutoshape, not aPicture, sohandle_shape_contentonly took the text path. A picture-filled shape with no text was skipped silently, and its image was lost.This change adds
_picture_fill_rid(), which returns ther:embedid of a shape'sp:spPr/a:blipFill/a:blip. When aShapehas one,_handle_picturesreads the image from the related image part (shape.part.related_part(rid).image) and adds aPictureItemwith the shape's provenance, the same way it does for ap:pic, including the existing malformed-image and metafile handling. Any text in the shape is still added after the picture. Fills that only link an external image (r:link) are left out because there are no bytes in the package.p:picshapes, groups and placeholders are unchanged.Issue resolved by this Pull Request:
Resolves #4988
Checklist:
_picture_fill_rid)Review evidence:
PictureItem(image/png, the original 64x32 size, page 1 provenance with the shape's bbox).tests/test_backend_pptx.py:test_pptx_picture_filled_shape_is_extracted: the issue's case.test_pptx_picture_filled_shape_keeps_its_text: the picture and the shape's text are both kept.test_pptx_linked_picture_fill_is_ignored: a linked fill adds no picture and the text is kept.mainand pass with the change. The third passes on both and guards the linked case.uv run pytest tests/test_backend_pptx*.py: 82 passed. None of the PPTX files intests/datahas a picture-filledp:sp, so no reference data changed.ruff format --checkandruff checkare clean.ty check docling/backend/mspowerpoint_backend.pyreports the same 7 diagnostics as onmain, all on unchanged lines.This fix was prepared with AI assistance; I reviewed the change and ran the checks above.