批量把图片转换成 PPT
概述
这个 Python 脚本可用于批量将多张图片转换成 PowerPoint 文件(PPT)。
代码示例
以下是 Python 代码示例,使用 pptx
库实现图片批量插入到 PPT 中:
from pptx import Presentation
from pptx.util import Inches
# 图片文件列表
image_files = []
for item in range(1, 76):
root_path = f"C:\\Users\\IMP\\Desktop\\ARM\\WEEK2\\images\\{item}.png"
image_files.append(root_path)
# 创建一个空白的 PPT
prs = Presentation()
# 遍历图片文件列表,将每张图片插入到 PPT 中
for image_file in image_files:
slide = prs.slides.add_slide(prs.slide_layouts[5])
left_inch = Inches(0)
top_inch = Inches(0)
width_inch = prs.slide_width
height_inch = prs.slide_height
slide.shapes.add_picture(image_file, left_inch, top_inch, width_inch, height_inch)
# 保存 PPT 文件
prs.save("C:\\Users\\IMP\\Desktop\\ARM\\WEEK2\\images1.pptx")