如何在python pptx中设置背景图像

如何在python pptx中设置背景图像,python,python-3.x,powerpoint,python-pptx,Python,Python 3.x,Powerpoint,Python Pptx,我目前正在做一个项目,旨在创建一个pptx。然而,我试图设置一个图像作为幻灯片的背景,我似乎无法在Python pptx的文档中找到解决方案。是否可以将图像设置为背景,如果可以,有人可以帮助我吗?如果不是,是否有人知道另一个使用python的解决方案 多谢各位 import os import fnmatch from pptx import Presentation #Create presentation and setting layout as blank (6) prs = Pres

我目前正在做一个项目,旨在创建一个pptx。然而,我试图设置一个图像作为幻灯片的背景,我似乎无法在Python pptx的文档中找到解决方案。是否可以将图像设置为背景,如果可以,有人可以帮助我吗?如果不是,是否有人知道另一个使用python的解决方案

多谢各位

import os
import fnmatch
from pptx import Presentation

#Create presentation and setting layout as blank (6)
prs = Presentation()
blank_slide_layout = prs.slide_layouts[6]

#Find number of slides to create
#First Method = Count number of images in screenshot files (change path depending on the user)
nbSlide = len(fnmatch.filter(os.listdir("mypath"), '*.jpeg'))

#Loop to create as number of slides as there is report pages
for i in range(nbSlide):
    slide = prs.slides.add_slide(blank_slide_layout)
    #change background with an image of the slide …
    background=slide.background

#Final step = Creation and saving of pptx
prs.save('test.pptx')
是否可以将图像设置为背景

到目前为止,使用
pythonpptx
还没有直接的方法插入图像作为幻灯片的背景

如果不是,是否有人知道另一个使用python的解决方案

考虑到适当的宽度/高度参数,您可以定期将感兴趣的图片插入到给定的幻灯片中:

#Loop to create as number of slides as there is report pages
for i in range(nbSlide):
    slide = prs.slides.add_slide(blank_slide_layout)
    #change background with an image of the slide …
    left = top = 0
    pic = slide.shapes.add_picture('/your_file.jpeg', left-0.1*prs.slide_width, top, height = prs.slide_height)