python插入图片到powerpoint,如何设置图片的宽高?
回答问题 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
·
回答问题
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))
更多推荐
目录
所有评论(0)