当前位置: 首页 > 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

相关文章:

  • MYSQL(三)--服务器启动参数与配置
  • 云服务器代理商的合作模式
  • 【信息系统项目管理师-选择真题】2025上半年(第一批)综合知识答案和详解
  • 每日算法-250605
  • JVM 类初始化和类加载 详解
  • 代码训练LeetCode(24)数组乘积
  • LeetCode 热题 100 - 哈希 - 128
  • ES6中的Map与Set数据结构的简单应用
  • 自定义注解facade 实现切面 进行日志记录和参数校验
  • Python训练第四十五天
  • 类似东郊到家app系统源码开发
  • 设计模式-2 结构型模式
  • 2025年- H71-Lc179--39.组合总和(回溯,组合)--Java版
  • Jenkins | Linux环境部署Jenkins与部署java项目
  • 【学习笔记】Lamba表达式[匿名函数]
  • `sendto()` / `recvfrom()` - 发送/接收数据(UDP)
  • this.$set() 的用法详解(Vue响应式系统相关)
  • 基于值函数的强化学习算法之Double Q-Learning详解
  • 示波器电流探头校准规范指南
  • 软考 系统架构设计师系列知识点之杂项集萃(81)
  • 网站租用服务器多少钱/班级优化大师官网登录
  • 扁平风网站/站长工具的网址
  • 网站前缀带wap的怎么做/app注册拉新平台
  • 一个网站绑定两个域名/优化提升
  • 网站交换链接怎么做?/市场宣传推广方案
  • 网站制作咨询公司/百度网络推广营销