New to python-pptx package. https://python-pptx.readthedocs.io/en/latest/ Would like to insert pictures to powerpoint. How can I set the width and height of the picture?
Code I have now:
from pptx import Presentation
from pptx.util import Inches
img_path = 'monty-truth.png'
prs = Presentation()
blank_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_slide_layout)
left = top = Inches(1)
pic = slide.shapes.add_picture(img_path, left, top)
prs.save('test.pptx')
Click the picture, shape, text box, or WordArt that you want to resize. Do one of the following: To resize a picture, under Picture Tools, on the Format tab, in the Size group, enter the measurements that you want into the Height and Width boxes.
When inserting pictures, how can you avoid distorting the pictureif it is resized later? Use best scale for slide show. Lock the aspect ratio. Compress the picture.
Click File > Options > Advanced. Under Image Size and Quality, select High fidelity in the Default resolution list.
Parameters of add_picture
are:
add_picture(image_file, left, top, width=None, height=None)
To set the picture width and height, you just need to define the width and height parameters. In one of my projects, I got good picture height and placement with the following settings:
pic = slide.shapes.add_picture(img_path, pptx.util.Inches(0.5), pptx.util.Inches(1.75),
width=pptx.util.Inches(9), height=pptx.util.Inches(5))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With