You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add InlineShape.image — extract the picture behind a shape #124
InlineShape exposes width, height, type and description (src/docx/shape.py:299). There is no way to get at the image itself.
Extracting the pictures from a document — the obvious counterpart to add_picture() — currently means walking document.part.rels by hand, filtering on reltype, and matching parts up to shapes yourself. The shape knows its r:embed; it just does not tell anyone.
python-pptx has had Picture.image returning an Image with .blob, .ext, .content_type, .size and .dpi for years, and the ImagePart / Image classes it needs already exist here — parts/image.py and image/image.py. This is plumbing, not new machinery.
Document.images or similar as the collection-level convenience, if it falls out cleanly
Watch out for
shape.type can be LINKED_PICTURE, where the blip carries r:link rather than r:embed and the bytes are not in the package at all. Return |None| or raise something specific; do not let it fail with a KeyError on the relationship lookup.
A shape can be a chart, a SmartArt diagram or an embedded object rather than a picture. WD_INLINE_SHAPE.NOT_IMPLEMENTED already exists for those; .image should be |None| there rather than guessing.
An SVG picture (2.0.0) has two blips — the SVG in an asvg:svgBlip extension and a raster fallback in the ordinary a:blip. Decide which .image returns; returning the fallback and adding .svg_image for the other is probably right, since the fallback is what every consumer can actually decode.
Several shapes can share one image part. Do not assume a one-to-one mapping when building any collection view.
Upstream: "feature: InlineShape.image ?", and the recurring "how do I extract the images from a docx".
Landed in #139. InlineShape.image, FloatingShape.image, .svg_image and Document.images. Each case the issue flagged is handled: a linked picture, a chart or SmartArt, and a shape with no part behind it all give None rather than a KeyError; .image returns the raster fallback of an SVG and .svg_image the vector source; several shapes sharing one image part give one entry in Document.images.
Activity
fix: review findings from the 2.0.0 issue sweep
toxicphreAK commentedon Aug 5, 2026
Landed in #139.
InlineShape.image,FloatingShape.image,.svg_imageandDocument.images. Each case the issue flagged is handled: a linked picture, a chart or SmartArt, and a shape with no part behind it all giveNonerather than aKeyError;.imagereturns the raster fallback of an SVG and.svg_imagethe vector source; several shapes sharing one image part give one entry inDocument.images.