I am working on powerpoints using python.pptx, where I am struggling to save certain picture from a slide to local system.Can anyone suggest me how to do it?
Until now : I am able to print the shape, But dont know how to save the picture as we do with presentation using prs.save.
prs =Presentation('mypath/myPowerpoint.pptx')
slide2 = prs.slides[1] #i want to save picture in slide 2
pic = slide2.shapes[4] # i have check shape 5 is the picture
print(pic.name) # i am able to print the picture name
pic.save('Mypic.jpg') #------ this didn't work --------
Thanks in advance.
An image depicted in a Picture
shape can be accessed using its image
property. The Image object provides access to detailed properties of the image, including the bytes of the image file itself.
http://python-pptx.readthedocs.io/en/latest/api/shapes.html#pptx.shapes.picture.Picture.image
http://python-pptx.readthedocs.io/en/latest/api/image.html#pptx.parts.image.Image
So, for example:
with open('mypic.jpg', 'wb') as f:
f.write(pic.image.blob)
来源:https://stackoverflow.com/questions/48455680/how-to-download-or-save-a-picture-from-a-powerpoint-ppt-with-python-pptx