Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python-pptx: insert picture into content placeholder

I'm using python-pptx 0.6.0 and I created a slide with content with caption. I want to insert picture into the content placeholder but there is no attribute such as add_picture or insert_picuture to use. How can I add picture into this content placeholder? Thanks for answering my question :)

like image 476
Rhinoo Rhino Avatar asked Sep 28 '16 10:09

Rhinoo Rhino


1 Answers

See the documentation on Understanding placeholders and Working with placeholders.

In brief, using something like this, you get the placeholder from the slide, then call insert_picture on the placeholder:

>>> prs = Presentation()
>>> slide = prs.slides.add_slide(prs.slide_layouts[8])
>>> placeholder = slide.placeholders[1]  # idx key, not position
>>> placeholder.name
'Picture Placeholder 2'
>>> placeholder.placeholder_format.type
PICTURE (18)
>>> picture = placeholder.insert_picture('my-image.png')

Note that this only works with a picture placeholder. You'll need to replace any "general purpose" content placeholder with one specific to what you're going to insert.

like image 95
scanny Avatar answered Oct 10 '22 01:10

scanny