Reputation: 7335
I have a Powerpoint presentation with images. On each of the image is a straight line (connector) and a circle drawn by hand (shape). [medical image with highlited features]
My goal is to extract image, line and the circle as a separate pictures (.jpeg). I am able to extract the image, but I fail to do so with the rest.
This is what works with the image:
ultrasound = shape.image
image_bytes = ultrasound.blob
with open(path, 'wb') as f:
f.write(image_bytes)
Of course when I try the same with the line and shape, I get an error:
AttributeError: 'Shape' object has no attribute 'blob'
AttributeError: 'Connector' object has no attribute 'blob'
I suppose there should be a way, because I when I right-click on the line/shape, there is an option Save As Picture...
Upvotes: 0
Views: 2488
Reputation: 28903
This behavior depends on the PowerPoint renderer and is not supported in python-pptx
. Shapes are vector objects, so you could pursue that approach somehow, like recreating images with a drawing library that have the same characteristics like start, point, end-point, width and height, etc. Pillow
(PIL
) allows you to "draw" bitmapped images with primitives like lines and I expect ellipses, which might get it done for you in this case.
Upvotes: 1