当前位置: 首页 > news >正文

PPT转图片拼贴工具 v3.0

软件介绍

这个软件就是将PPT文件转换为图片并且拼接起来。

这个代码支持导入单个文件也支持导入文件夹

但是目前还没有解决可视化界面问题。

效果展示

软件源码

import os
import re
import win32com.client
from PIL import Image
from typing import List, Uniondef convert_ppt_to_png(ppt_path: str, output_folder: str) -> None:"""将单个PPT文件转换为PNG图片"""try:ppt_app = win32com.client.Dispatch("PowerPoint.Application")except Exception as e:raise RuntimeError(f"无法启动 PowerPoint 应用程序: {e}")if not os.path.exists(ppt_path):raise FileNotFoundError(f"PPT 文件不存在: {ppt_path}")presentation = ppt_app.Presentations.Open(ppt_path, WithWindow=False)presentation.SaveAs(output_folder, 18)  # 18 代表 PNG 格式presentation.Close()ppt_app.Quit()def create_collage(input_folder: str, output_folder: str, ppt_name: str, row_size: int = 3, col_gap: int = 10, row_gap: int = 10) -> None:"""从PNG图片创建拼贴画"""# 获取所有幻灯片图片files = os.listdir(input_folder)slide_files = [f for f in files if re.match(r"幻灯片\d+\.png", f, re.IGNORECASE)]if not slide_files:raise RuntimeError(f"未找到幻灯片图片文件")# 按幻灯片序号排序slide_files.sort(key=lambda x: int(re.search(r'\d+', x).group()))# 打开所有图片try:images = [Image.open(os.path.join(input_folder, f)) for f in slide_files]except Exception as e:raise RuntimeError(f"加载图片时出错: {e}")if not images:raise RuntimeError("没有可处理的图片")width, height = images[0].size# 第一行放大显示封面first_img = images[0].resize((width * row_size + col_gap * (row_size - 1), height * row_size + int(col_gap * (row_size - 1) * height / width)), Image.LANCZOS)remaining_images = images[1:]# 计算画布尺寸rows = (len(remaining_images) + row_size - 1) // row_sizecanvas_width = first_img.widthcanvas_height = first_img.height + rows * (height + row_gap)# 创建拼贴画布collage_image = Image.new("RGB", (canvas_width, canvas_height), (255, 255, 255))# 粘贴封面collage_image.paste(first_img, (0, 0))# 粘贴剩余幻灯片for i, img in enumerate(remaining_images):row = i // row_sizecol = i % row_sizex = col * (width + col_gap)y = first_img.height + row * (height + row_gap)collage_image.paste(img, (x, y))# 保存拼贴画collage_path = os.path.join(output_folder, f"{ppt_name}.png")collage_image.save(collage_path)# 删除临时PNG文件for f in slide_files:os.remove(os.path.join(input_folder, f))def process_ppt_item(item_path: str, output_folder: str, row_size: int = 3, col_gap: int = 10, row_gap: int = 10) -> None:"""处理单个PPT文件或文件夹"""if os.path.isfile(item_path):# 处理单个PPT文件if item_path.lower().endswith(('.ppt', '.pptx')):ppt_filename = os.path.basename(item_path)ppt_name = os.path.splitext(ppt_filename)[0]# 转换PPT为PNGconvert_ppt_to_png(item_path, output_folder)# 创建拼贴画create_collage(output_folder, output_folder, ppt_name, row_size, col_gap, row_gap)print(f"✓ 处理完成: {ppt_name}.png")else:print(f"⚠️ 跳过非PPT文件: {os.path.basename(item_path)}")elif os.path.isdir(item_path):# 处理文件夹print(f"处理文件夹: {item_path}")for filename in os.listdir(item_path):file_path = os.path.join(item_path, filename)if file_path.lower().endswith(('.ppt', '.pptx')):process_ppt_item(file_path, output_folder, row_size, col_gap, row_gap)else:print(f"⚠️ 路径不存在或无法访问: {item_path}")if __name__ == "__main__":# 用户配置区域input_path = r'D:\Desktop\文件存储\1'  # 可以是文件或文件夹路径output_folder = r'D:\Desktop\文件存储\1'  # 输出文件夹路径row_size = 3  # 每行图片数量col_gap = 10  # 列间距(像素)row_gap = 10  # 行间距(像素)# 确保输出文件夹存在os.makedirs(output_folder, exist_ok=True)print("开始处理PPT文件...")process_ppt_item(input_path, output_folder, row_size, col_gap, row_gap)print("\n全部处理完成!")input("按回车键退出...")    

源码下载

https://pan.quark.cn/s/100eea4e778f

http://www.xdnf.cn/news/878653.html

相关文章:

  • 鸿蒙仓颉语言开发实战教程:商城搜索页
  • 开关机、重启、改密、登录:图解腾讯云CVM日常管理核心操作,轻松掌控你的云主机
  • K8S认证|CKS题库+答案| 2. Pod 指定 ServiceAccount
  • k8s业务程序联调工具-KtConnect
  • Github Copilot新特性:Copilot Spaces-成为某个主题的专家
  • 【Web应用】若依框架:基础篇21二次开发-页面调整
  • 《C++初阶之类和对象》【命名空间 + 输入输出 + 缺省参数 + 函数重载】
  • OCR助力保险业建设
  • Redis持久化模式RDB与AOF
  • [论文阅读] 人工智能+项目管理 | 当 PMBOK 遇见 AI:传统项目管理框架的破局之路
  • Go语言学习笔记-创建一个Go项目
  • 瑞典Sana Agents全国部署:AI驱动的数字化转型革命
  • 适用于vue3的大屏数据展示组件库DataV(踩坑版)
  • Jenkins | Jenkins构建成功服务进程关闭问题
  • OD 算法题 B卷【BOSS的收入】
  • Docker Compose 备忘
  • 通过BUG(prvIdleTask、pxTasksWaitingTerminatio不断跳转问题)了解空闲函数(prvIdleTask)和TCB
  • 【C++ Qt】窗口(Qt窗口框架、菜单栏QMenuBar)
  • 高效集成AI能力:使用开放API打造问答系统,不用训练模型,也能做出懂知识的AI
  • Spring MVC 之 异常处理
  • 《一生一芯》数字实验六:实现随机数发生器
  • 联邦学习架构深度分析:支持多家医院协作训练AI模型方案分析
  • Python-多线程
  • 得力Deli GE330W打印机信息
  • 【HW系列】—内网被渗透的解决方案
  • 我也不知道
  • 在C++中,头文件(.h或.hpp)的标准写法
  • 高效使用AI大模型:测试工程师提示词编写框架
  • 小白初学SpringBoot记录
  • LeetCode 热题 100 739. 每日温度