0

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...

Community
  • 1
  • 1
HonzaB
  • 7,065
  • 6
  • 31
  • 42

1 Answers1

1

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.

scanny
  • 26,423
  • 5
  • 54
  • 80
  • Thanks for taking the time to answer. In the end, I used VBA to extract the shapes. But good to know for future cases. – HonzaB Jan 11 '19 at 09:31