Python PPTX库设置背景图片教程
以下是使用Python的pptx库写一段设置PPT背景图片的程序的示例代码:
from pptx import Presentation
from pptx.util import Inches
# 创建PPT对象
prs = Presentation()
# 设置PPT背景图
slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(slide_layout)
background = slide.background
background_picture = background.background_pic
# 设置背景图文件路径
bg_img_path = 'background_image.jpg'
# 添加背景图片
background_picture.set_image(bg_img_path)
# 保存PPT
prs.save('my_presentation.pptx')
这段程序中,首先创建了一个PPT对象,然后使用slide_layouts[0]选择了第一种幻灯片布局,创建了一个幻灯片,并将该幻灯片作为背景。接着,使用background.background_pic获取了背景图片对象,将其图片文件路径设置为bg_img_path,最后保存PPT。
原文地址: https://www.cveoy.top/t/topic/nlej 著作权归作者所有。请勿转载和采集!