回答问题

python-pptx 包的新功能。https://python-pptx.readthedocs.io/en/latest/想插入图片到powerpoint。如何设置图片的宽度和高度?

我现在拥有的代码:

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')

Answers

add_picture的参数为:

add_picture(image_file, left, top, width=None, height=None)

设置图片的宽高,只需要定义宽高参数即可。在我的一个项目中,我通过以下设置获得了良好的图片高度和位置:

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))
Logo

学AI,认准AI Studio!GPU算力,限时免费领,邀请好友解锁更多惊喜福利 >>>

更多推荐