@dickpy/dsh-oil-slide 0.0.0-stage → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +89 -2
  3. package/bundled-assets/brand/empty-deck-cobalt.webp +0 -0
  4. package/bundled-assets/brand/oil-slide-mark-512.png +0 -0
  5. package/bundled-assets/skill/LICENSE +21 -0
  6. package/bundled-assets/skill/README.md +61 -0
  7. package/bundled-assets/skill/SKILL.md +185 -0
  8. package/bundled-assets/skill/references/art-directions.md +99 -0
  9. package/bundled-assets/skill/references/brand-and-canvas.md +72 -0
  10. package/bundled-assets/skill/references/design-baseline.txt +1 -0
  11. package/bundled-assets/skill/references/prompt-compiler.md +99 -0
  12. package/bundled-assets/skill/references/restore-and-pptx.md +178 -0
  13. package/bundled-assets/skill/references/staged-pptx.md +71 -0
  14. package/bundled-assets/skill/scripts/_runtime_utils.py +351 -0
  15. package/bundled-assets/skill/scripts/asset_sheet.py +528 -0
  16. package/bundled-assets/skill/scripts/brand_ref.py +776 -0
  17. package/bundled-assets/skill/scripts/crop_asset.py +1709 -0
  18. package/bundled-assets/skill/scripts/deck_shell.py +2322 -0
  19. package/bundled-assets/skill/scripts/export_images.py +280 -0
  20. package/bundled-assets/skill/scripts/extract_pptx.py +360 -0
  21. package/bundled-assets/skill/scripts/extract_slide_dom.js +1640 -0
  22. package/bundled-assets/skill/scripts/html_to_pptx.py +4042 -0
  23. package/bundled-assets/skill/scripts/measure_slide_layout.py +952 -0
  24. package/bundled-assets/skill/scripts/oiloil-connect.mjs +1493 -0
  25. package/bundled-assets/skill/scripts/oiloil-image.mjs +492 -0
  26. package/bundled-assets/skill/scripts/prepare_plate.py +412 -0
  27. package/bundled-assets/skill/scripts/render_gradient.py +258 -0
  28. package/bundled-assets/skill/scripts/slide_brand.py +111 -0
  29. package/bundled-assets/skill/scripts/slide_incremental.py +122 -0
  30. package/bundled-assets/skill/scripts/slide_workflow.py +711 -0
  31. package/bundled-assets/skill/scripts/verify_deck.py +3483 -0
  32. package/bundled-assets/skill/vendor/README.md +4 -0
  33. package/bundled-assets/skill/vendor/codex-ppt/LICENSE +21 -0
  34. package/bundled-assets/skill/vendor/codex-ppt/assemble_ppt.py +435 -0
  35. package/bundled-assets/skill/vendor/codex-ppt/codex_ppt_runtime.py +284 -0
  36. package/bundled-assets/skill/vendor/codex-ppt/image_gen.py +972 -0
  37. package/bundled-assets/skill/vendor/codex-ppt/image_providers/__init__.py +6 -0
  38. package/bundled-assets/skill/vendor/codex-ppt/image_providers/atlascloud.py +222 -0
  39. package/bundled-assets/skill/vendor/codex-ppt/image_providers/base.py +32 -0
  40. package/bundled-assets/skill/vendor/codex-ppt/image_providers/factory.py +21 -0
  41. package/bundled-assets/skill/vendor/codex-ppt/image_providers/openai_compatible.py +238 -0
  42. package/bundled-assets/skill/vendor/codex-ppt/requirements.txt +5 -0
  43. package/bundled-assets/skill/vendor/codex-ppt/styles//345/205/232/346/224/277/347/272/242/351/243/216/346/240/274.md +98 -0
  44. package/bundled-assets/skill/vendor/codex-ppt/styles//345/210/233/346/204/217/346/235/202/345/277/227/351/243/216.md +72 -0
  45. package/bundled-assets/skill/vendor/codex-ppt/styles//345/244/215/345/217/244/346/211/201/345/271/263/346/217/222/347/224/273/351/243/216.md +72 -0
  46. package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/346/212/200/346/234/257/350/247/243/351/207/212/351/243/216.md +86 -0
  47. package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/347/231/275/346/235/277/351/243/216.md +72 -0
  48. package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/231/345/255/246/350/257/276/344/273/266/351/243/216.md +107 -0
  49. package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/260/346/215/256/344/273/252/350/241/250/347/233/230/351/243/216.md +73 -0
  50. package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/205/347/210/275/344/270/223/344/270/232/351/243/216.md +87 -0
  51. package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/251/346/232/226/346/211/213/345/267/245/351/243/216.md +72 -0
  52. package/bundled-assets/skill/vendor/codex-ppt/styles//347/224/265/345/255/220/345/242/250/346/260/264/346/235/202/345/277/227/351/243/216.md +86 -0
  53. package/bundled-assets/skill/vendor/codex-ppt/styles//347/247/221/347/240/224/347/255/224/350/276/251/351/243/216.md +138 -0
  54. package/bundled-assets/skill/vendor/codex-ppt/styles//351/272/246/350/202/257/351/224/241/351/243/216/346/240/274.md +119 -0
  55. package/bundled-assets/skill/vendor/image-to-editable-ppt/LICENSE +21 -0
  56. package/bundled-assets/skill/vendor/image-to-editable-ppt/SKILL.md +171 -0
  57. package/bundled-assets/skill/vendor/image-to-editable-ppt/agents/openai.yaml +4 -0
  58. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/__init__.py +1 -0
  59. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/cli.py +25 -0
  60. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/__init__.py +1 -0
  61. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_input_normalization.py +355 -0
  62. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_page_artifacts.py +132 -0
  63. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/build_pptx_from_manifest.py +1029 -0
  64. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/configure_image_backend.py +52 -0
  65. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_run_state.py +214 -0
  66. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_text_hints.py +179 -0
  67. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/finalize_deck_run.py +96 -0
  68. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/formula_renderer.py +254 -0
  69. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/image_gen.py +206 -0
  70. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/main.py +795 -0
  71. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/make_page_contact_sheet.py +28 -0
  72. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/native_tables.py +140 -0
  73. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/paddle_text_hints.py +212 -0
  74. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_job_status.py +54 -0
  75. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_text_metrics.py +334 -0
  76. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/path_geometry.py +174 -0
  77. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/prepare_deck_run.py +209 -0
  78. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/process_asset_sheet.py +104 -0
  79. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_imagegen_result.py +118 -0
  80. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_dispatch.py +83 -0
  81. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_result.py +130 -0
  82. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/remove_chroma_key.py +441 -0
  83. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/reset_page_job.py +74 -0
  84. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/runtime_env.py +283 -0
  85. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/split_alpha_components.py +323 -0
  86. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/text_hints.py +309 -0
  87. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/validate_pptx.py +873 -0
  88. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/pyproject.toml +29 -0
  89. package/bundled-assets/skill/vendor/image-to-editable-ppt/prompts/page-worker.md +47 -0
  90. package/bundled-assets/skill/vendor/image-to-editable-ppt/references/cli-helper.md +282 -0
  91. package/bundled-assets/skill/vendor/image-to-editable-ppt/references/manifest-schema.md +423 -0
  92. package/bundled-assets/skill/vendor/image-to-editable-ppt/references/page-decision-tree.md +301 -0
  93. package/bundled-assets/skill/vendor/image-to-editable-ppt/scripts/build-page-worker-prompt.py +134 -0
  94. package/cordis.patch.yml +3 -0
  95. package/lib/client.js +11282 -0
  96. package/lib/index.js +2638 -0
  97. package/package.json +140 -4
@@ -0,0 +1,4 @@
1
+ # Third-party integrations (MIT)
2
+
3
+ - [ningzimu/codex-ppt-skill](https://github.com/ningzimu/codex-ppt-skill/tree/781c3cc1a29fe91bda3392b684d104a13342dace) at `781c3cc1a29fe91bda3392b684d104a13342dace`: adapted outline/sample review approach; bundled style documents, image provider CLI, and image PPTX assembler. The assembler adds Oil Slide's ratios and a lossless input mode. Source files are kept in `codex-ppt/`, with the original LICENSE.
4
+ - [ningzimu/image-to-editable-ppt-skill](https://github.com/ningzimu/image-to-editable-ppt-skill/tree/b7be494e31a0ed56ef98716891db5474606b8cdf) at `b7be494e31a0ed56ef98716891db5474606b8cdf`: reference implementation and worker guide in `image-to-editable-ppt/` with its original LICENSE. Oil Slide supplies the exact approved pages and uses `editppt` to orchestrate and validate conversion. This fork adds `prepare --serial-local` for hosts that reconstruct every page in the same conversation.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ningzimu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,435 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ PPT 组装脚本
4
+
5
+ 将一个目录中的幻灯片图片组装成 PowerPoint 演示文稿。
6
+ 每张图片会被插入为一页幻灯片,充满整个页面。
7
+ """
8
+
9
+ import argparse
10
+ import os
11
+ import re
12
+ import sys
13
+ import tempfile
14
+ from typing import Dict, List, Optional, Tuple
15
+
16
+
17
+ def dependency_hint() -> str:
18
+ runtime_home = os.path.expanduser(os.environ.get("CODEX_PPT_HOME", "~/.codex-ppt-skill"))
19
+ python = os.path.join(
20
+ runtime_home,
21
+ ".venv",
22
+ "Scripts" if os.name == "nt" else "bin",
23
+ "python.exe" if os.name == "nt" else "python",
24
+ )
25
+ runtime_script = os.path.join(
26
+ os.path.dirname(os.path.abspath(__file__)),
27
+ "codex_ppt_runtime.py",
28
+ )
29
+ return (
30
+ f"请运行: python3 {runtime_script} bootstrap\n"
31
+ f"或直接运行: {python} -m pip install -r "
32
+ f"{os.path.join(os.path.dirname(os.path.abspath(__file__)), 'requirements.txt')}"
33
+ )
34
+
35
+
36
+ def get_slide_images(ppt_project_dir: str) -> List[str]:
37
+ """
38
+ 获取幻灯片图片文件列表,按页码排序
39
+
40
+ Args:
41
+ ppt_project_dir: PPT 项目目录(包含 origin_image 子目录)
42
+
43
+ Returns:
44
+ 按顺序排列的图片文件路径列表
45
+ """
46
+ # 从 origin_image 子目录读取
47
+ origin_image_dir = os.path.join(ppt_project_dir, "origin_image")
48
+
49
+ if not os.path.exists(origin_image_dir):
50
+ print(f"错误:origin_image 目录不存在: {origin_image_dir}")
51
+ return []
52
+
53
+ print(f"从 origin_image 目录读取图片: {origin_image_dir}")
54
+
55
+ # 支持的图片格式
56
+ image_extensions = {'.png', '.jpg', '.jpeg', '.gif', '.bmp'}
57
+
58
+ # 只获取正式幻灯片图片,避免 sample_slide.png、草稿图或参考图被误装入 PPT。
59
+ slide_name_pattern = re.compile(r"^slide_(\d+)\.(png|jpe?g|gif|bmp)$", re.IGNORECASE)
60
+ image_files = []
61
+ for file in os.listdir(origin_image_dir):
62
+ file_path = os.path.join(origin_image_dir, file)
63
+ if os.path.isfile(file_path):
64
+ ext = os.path.splitext(file)[1].lower()
65
+ if ext in image_extensions and slide_name_pattern.match(file):
66
+ image_files.append(file_path)
67
+
68
+ def slide_sort_key(path: str) -> Tuple[int, str]:
69
+ filename = os.path.basename(path)
70
+ stem = os.path.splitext(filename)[0]
71
+ return (int(re.search(r"^slide_(\d+)", stem).group(1)), filename.lower())
72
+
73
+ # 按页码排序,避免 slide_10 排在 slide_2 前面。
74
+ # 同页码多文件时按文件名稳定排序。
75
+ image_files.sort(key=slide_sort_key)
76
+
77
+ return image_files
78
+
79
+
80
+ def load_speaker_notes(ppt_project_dir: str) -> Dict[int, str]:
81
+ """
82
+ 从 speech.md 读取每页演讲备注。
83
+
84
+ 支持以下标题格式:
85
+ - ## Slide 1: 标题
86
+ - ### Slide 1: 标题
87
+ - ## 第 1 页:标题
88
+ """
89
+ speech_path = os.path.join(ppt_project_dir, "speech.md")
90
+ if not os.path.exists(speech_path):
91
+ return {}
92
+
93
+ with open(speech_path, "r", encoding="utf-8") as f:
94
+ content = f.read()
95
+
96
+ notes: Dict[int, str] = {}
97
+ current_slide: Optional[int] = None
98
+ current_lines: List[str] = []
99
+ heading_pattern = re.compile(r"^#{2,4}\s*(?:Slide\s*(\d+)|第\s*(\d+)\s*页)\b.*$", re.IGNORECASE)
100
+
101
+ def flush_current() -> None:
102
+ if current_slide is None:
103
+ return
104
+ text = "\n".join(current_lines).strip()
105
+ if text:
106
+ notes[current_slide] = text
107
+
108
+ for line in content.splitlines():
109
+ match = heading_pattern.match(line.strip())
110
+ if match:
111
+ flush_current()
112
+ current_slide = int(match.group(1) or match.group(2))
113
+ current_lines = []
114
+ continue
115
+
116
+ if current_slide is not None:
117
+ current_lines.append(line)
118
+
119
+ flush_current()
120
+ return notes
121
+
122
+
123
+ def compress_image_if_needed(
124
+ image_path: str,
125
+ max_size_mb: float = 2.0,
126
+ quality_step: int = 5
127
+ ) -> Optional[str]:
128
+ """
129
+ 如果图片超过指定大小,压缩图片并返回临时文件路径
130
+
131
+ Args:
132
+ image_path: 原始图片路径
133
+ max_size_mb: 最大文件大小(MB)
134
+ quality_step: 每次降低的质量步进
135
+
136
+ Returns:
137
+ str: 如果需要压缩,返回临时文件路径;否则返回 None
138
+ """
139
+ max_size_bytes = max_size_mb * 1024 * 1024
140
+
141
+ # 检查原始文件大小
142
+ file_size = os.path.getsize(image_path)
143
+
144
+ if file_size <= max_size_bytes:
145
+ # 不需要压缩
146
+ return None
147
+
148
+ print(f" 图片大小 {file_size / 1024 / 1024:.2f}MB,需要压缩...")
149
+
150
+ try:
151
+ from PIL import Image
152
+
153
+ # 打开图片
154
+ img = Image.open(image_path)
155
+
156
+ # 转换 RGBA 到 RGB(如果需要保存为 JPEG)
157
+ if img.mode in ('RGBA', 'LA', 'P'):
158
+ background = Image.new('RGB', img.size, (255, 255, 255))
159
+ if img.mode == 'P':
160
+ img = img.convert('RGBA')
161
+ background.paste(img, mask=img.split()[-1] if img.mode in ('RGBA', 'LA') else None)
162
+ img = background
163
+
164
+ # 创建临时文件
165
+ temp_fd, temp_path = tempfile.mkstemp(suffix='.jpg')
166
+ os.close(temp_fd)
167
+
168
+ # 从高质量开始尝试压缩
169
+ quality = 95
170
+ while quality > 20:
171
+ img.save(temp_path, 'JPEG', quality=quality, optimize=True)
172
+ compressed_size = os.path.getsize(temp_path)
173
+
174
+ if compressed_size <= max_size_bytes:
175
+ print(f" 压缩成功: {compressed_size / 1024 / 1024:.2f}MB (质量: {quality})")
176
+ return temp_path
177
+
178
+ quality -= quality_step
179
+
180
+ # 如果还是太大,尝试调整尺寸
181
+ print(f" 质量压缩不足,尝试缩小尺寸...")
182
+ scale = 0.9
183
+ while scale > 0.3:
184
+ new_width = int(img.width * scale)
185
+ new_height = int(img.height * scale)
186
+ resized_img = img.resize((new_width, new_height), Image.Resampling.LANCZOS)
187
+
188
+ resized_img.save(temp_path, 'JPEG', quality=85, optimize=True)
189
+ compressed_size = os.path.getsize(temp_path)
190
+
191
+ if compressed_size <= max_size_bytes:
192
+ print(f" 压缩成功: {compressed_size / 1024 / 1024:.2f}MB (缩放: {scale:.0%})")
193
+ return temp_path
194
+
195
+ scale -= 0.1
196
+
197
+ # 实在压不下去了,返回最后的结果
198
+ print(f" 警告:无法压缩到 {max_size_mb}MB 以下,使用最小尺寸版本")
199
+ return temp_path
200
+
201
+ except ImportError:
202
+ print("错误:未安装 Pillow 库")
203
+ print(dependency_hint())
204
+ return None
205
+ except Exception as e:
206
+ print(f" 警告:图片压缩失败: {e}")
207
+ if 'temp_path' in locals() and os.path.exists(temp_path):
208
+ os.remove(temp_path)
209
+ return None
210
+
211
+
212
+ def create_presentation(
213
+ image_files: List[str],
214
+ output_path: str,
215
+ aspect_ratio: str = "16:9",
216
+ speaker_notes: Optional[Dict[int, str]] = None,
217
+ preserve_pixels: bool = False,
218
+ ) -> bool:
219
+ """
220
+ 创建 PowerPoint 演示文稿
221
+
222
+ Args:
223
+ image_files: 幻灯片图片文件列表
224
+ output_path: 输出 PPT 文件路径
225
+ aspect_ratio: 幻灯片宽高比(16:9 或 4:3)
226
+
227
+ Returns:
228
+ bool: 成功返回 True,失败返回 False
229
+ """
230
+ try:
231
+ try:
232
+ from pptx import Presentation
233
+ from pptx.util import Inches
234
+ except ImportError:
235
+ print("错误:未安装 python-pptx 库")
236
+ print(dependency_hint())
237
+ return False
238
+
239
+ # 创建演示文稿
240
+ prs = Presentation()
241
+
242
+ # 设置幻灯片尺寸
243
+ if aspect_ratio not in {"16:9", "4:3", "3:4", "9:16", "1:1"}:
244
+ print(f"警告:不支持的宽高比 {aspect_ratio},使用默认值 16:9")
245
+ aspect_ratio = "16:9"
246
+ w, h = map(int, aspect_ratio.split(":"))
247
+ prs.slide_width = Inches(10 * w / max(w, h))
248
+ prs.slide_height = Inches(10 * h / max(w, h))
249
+
250
+ speaker_notes = speaker_notes or {}
251
+
252
+ # 添加每一页幻灯片
253
+ temp_files_to_cleanup = []
254
+ for i, image_path in enumerate(image_files, 1):
255
+ if not os.path.exists(image_path):
256
+ print(f"警告:图片文件不存在: {image_path}")
257
+ continue
258
+
259
+ # 压缩图片(如果需要)
260
+ compressed_path = None if preserve_pixels else compress_image_if_needed(image_path, max_size_mb=2.0)
261
+
262
+ # 使用压缩后的图片或原图
263
+ image_to_use = compressed_path if compressed_path else image_path
264
+
265
+ # 记录临时文件以便后续清理
266
+ if compressed_path:
267
+ temp_files_to_cleanup.append(compressed_path)
268
+
269
+ # 使用空白布局(索引 6)
270
+ blank_slide_layout = prs.slide_layouts[6]
271
+ slide = prs.slides.add_slide(blank_slide_layout)
272
+
273
+ # 将图片添加到幻灯片,充满整个页面
274
+ slide.shapes.add_picture(
275
+ image_to_use,
276
+ left=0,
277
+ top=0,
278
+ width=prs.slide_width,
279
+ height=prs.slide_height
280
+ )
281
+
282
+ note_text = speaker_notes.get(i)
283
+ if note_text:
284
+ notes_frame = slide.notes_slide.notes_text_frame
285
+ notes_frame.clear()
286
+ notes_frame.text = note_text
287
+
288
+ print(f"✓ 已添加第 {i} 页: {os.path.basename(image_path)}")
289
+
290
+ # 确保输出目录存在
291
+ output_dir = os.path.dirname(output_path)
292
+ if output_dir and not os.path.exists(output_dir):
293
+ os.makedirs(output_dir)
294
+
295
+ # 保存演示文稿
296
+ prs.save(output_path)
297
+ print(f"\n✓ PPT 文件已保存: {output_path}")
298
+ print(f" 总页数: {len(image_files)}")
299
+ if speaker_notes:
300
+ matched_notes = sum(1 for i in range(1, len(image_files) + 1) if speaker_notes.get(i))
301
+ print(f" 已写入备注: {matched_notes}/{len(image_files)} 页")
302
+
303
+ # 清理临时文件
304
+ for temp_file in temp_files_to_cleanup:
305
+ try:
306
+ if os.path.exists(temp_file):
307
+ os.remove(temp_file)
308
+ except Exception as e:
309
+ print(f"警告:清理临时文件失败 {temp_file}: {e}")
310
+
311
+ return True
312
+
313
+ except Exception as e:
314
+ print(f"错误:创建 PPT 失败: {e}")
315
+ import traceback
316
+ traceback.print_exc()
317
+
318
+ # 即使失败也要清理临时文件
319
+ if 'temp_files_to_cleanup' in locals():
320
+ for temp_file in temp_files_to_cleanup:
321
+ try:
322
+ if os.path.exists(temp_file):
323
+ os.remove(temp_file)
324
+ except:
325
+ pass
326
+
327
+ return False
328
+
329
+
330
+ def main():
331
+ parser = argparse.ArgumentParser(
332
+ description='将幻灯片图片组装成 PowerPoint 演示文稿',
333
+ formatter_class=argparse.RawDescriptionHelpFormatter,
334
+ epilog='''
335
+ 示例用法:
336
+ # 基本用法
337
+ # 会在 /path/to/base/ 下查找 MyPresentation/ 文件夹
338
+ # 从 MyPresentation/origin_image/ 读取图片
339
+ # 将 PPT 保存为 MyPresentation/MyPresentation.pptx
340
+ python assemble_ppt.py /path/to/base/ MyPresentation.pptx
341
+
342
+ # 指定 4:3 宽高比
343
+ python assemble_ppt.py /path/to/base/ MyPresentation.pptx --aspect-ratio 4:3
344
+
345
+ # 只初始化目录,不生成 PPT
346
+ python assemble_ppt.py /path/to/base/ MyPresentation.pptx --init
347
+
348
+ 文件夹结构要求:
349
+ /path/to/base/MyPresentation/
350
+ ├── origin_image/
351
+ │ ├── slide_01.png
352
+ │ ├── slide_02.png
353
+ │ └── ...
354
+ ├── speech.md (可选,将写入 PPT 备注)
355
+ └── MyPresentation.pptx (将在此生成)
356
+
357
+ 注意:
358
+ - 图片文件必须放在 origin_image 子目录中
359
+ - 只会读取 slide_01.png、slide_02.png 这类正式图片,其他图片会被忽略
360
+ - 图片文件按页码排序
361
+ - 建议图片文件命名为: slide_01.png, slide_02.png, ...
362
+ - 每张图片会充满整个幻灯片页面
363
+ - 如果项目目录下存在 speech.md,会按 Slide N 标题写入每页备注
364
+ '''
365
+ )
366
+
367
+ parser.add_argument('base_dir', help='基础目录(PPT 项目文件夹的父目录)')
368
+ parser.add_argument('output', help='输出 PPT 文件名 (.pptx)')
369
+ parser.add_argument('--aspect-ratio', '--ar',
370
+ choices=['16:9', '4:3'],
371
+ default='16:9',
372
+ help='幻灯片宽高比 (默认: 16:9)')
373
+ parser.add_argument('--init',
374
+ action='store_true',
375
+ help='只创建 PPT 项目目录和 origin_image 子目录,不生成 PPT')
376
+
377
+ args = parser.parse_args()
378
+
379
+ # 确保输出文件有 .pptx 扩展名
380
+ output_filename = args.output
381
+ if not output_filename.lower().endswith('.pptx'):
382
+ output_filename += '.pptx'
383
+
384
+ # 获取 PPT 名称(不含扩展名)
385
+ ppt_name = os.path.splitext(os.path.basename(output_filename))[0]
386
+
387
+ # 构建 PPT 项目目录
388
+ ppt_project_dir = os.path.join(args.base_dir, ppt_name)
389
+ origin_image_dir = os.path.join(ppt_project_dir, "origin_image")
390
+
391
+ if args.init:
392
+ os.makedirs(origin_image_dir, exist_ok=True)
393
+ print(f"✓ PPT 项目目录已准备好: {ppt_project_dir}")
394
+ print(f"✓ 幻灯片图片目录已准备好: {origin_image_dir}")
395
+ sys.exit(0)
396
+
397
+ if not os.path.exists(ppt_project_dir):
398
+ print(f"错误:PPT 项目目录不存在: {ppt_project_dir}")
399
+ print("如需初始化目录,请添加 --init 参数")
400
+ sys.exit(1)
401
+
402
+ if not os.path.exists(origin_image_dir):
403
+ print(f"错误:origin_image 目录不存在: {origin_image_dir}")
404
+ print("如需初始化目录,请添加 --init 参数")
405
+ sys.exit(1)
406
+
407
+ # 设置输出路径
408
+ output_path = os.path.join(ppt_project_dir, output_filename)
409
+
410
+ # 获取幻灯片图片
411
+ print(f"正在扫描 PPT 项目目录: {ppt_project_dir}")
412
+ image_files = get_slide_images(ppt_project_dir)
413
+
414
+ if not image_files:
415
+ print("错误:未找到任何图片文件")
416
+ print("支持的格式: .png, .jpg, .jpeg, .gif, .bmp")
417
+ print(f"\n请将幻灯片图片放置在: {origin_image_dir}/")
418
+ sys.exit(1)
419
+
420
+ print(f"找到 {len(image_files)} 张幻灯片图片\n")
421
+ speaker_notes = load_speaker_notes(ppt_project_dir)
422
+ if speaker_notes:
423
+ print(f"找到 {len(speaker_notes)} 页备注: {os.path.join(ppt_project_dir, 'speech.md')}\n")
424
+
425
+ # 创建演示文稿
426
+ print(f"正在创建 PPT (宽高比: {args.aspect_ratio})...")
427
+ print("-" * 50)
428
+
429
+ success = create_presentation(image_files, output_path, args.aspect_ratio, speaker_notes)
430
+
431
+ sys.exit(0 if success else 1)
432
+
433
+
434
+ if __name__ == '__main__':
435
+ main()