Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

feat(core): 实现图片驱动的自适应布局工作流

hugohe30b432f3ec972
diff --git a/roles/Executor_General.md b/roles/Executor_General.md
index 9774e0aa..94db33ac 100644
--- a/roles/Executor_General.md
+++ b/roles/Executor_General.md
@@ -22,6 +22,14 @@
- 使用 `<rect>` 定义背景色
- 使用《设计规范与内容大纲》中指定的字体方案
+- **图片适配布局**:
+ 生成含图片的页面时,**必须**检查《设计规范》中该图片的尺寸信息:
+ * 如果图片是**竖图**,严禁使用横向拉伸的布局,应使用 `<rect>` 创建竖向遮罩或容器。
+ * 如果图片是**宽图**,应避免在左右分栏的狭窄容器中显示,导致主体过小。
+ * 使用 `preserveAspectRatio` 时:
+ * 全屏背景用 `slice` (裁剪)。
+ * 完整展示数据图表用 `meet` (包含)。
+
### 字体使用
根据规范中的字体方案,为不同文本角色应用对应字体:
diff --git a/roles/Strategist.md b/roles/Strategist.md
index 52819b1c..5e31fb0a 100644
--- a/roles/Strategist.md
+++ b/roles/Strategist.md
@@ -118,6 +118,19 @@
- 中文:A=黑体系, B=宋体系, C=楷体系, D=标题黑, E=手写
- 英文:F=无衬线, G=衬线, H=标题, I=手写, J=等宽
+---\n
+## 1.5 图片资源扫描(针对“已有图片”模式)
+
+如果用户在第 g 项确认中选择了 **“B) 用户提供”**,你**必须**执行以下操作:
+
+1. **运行扫描工具**:使用 bash 运行 `python3 tools/analyze_images.py <项目路径>/images`。
+2. **读取图片数据**:获取工具输出的图片尺寸、比例和布局建议(Markdown 表格形式)。
+3. **整合进规范**:将扫描结果直接填入《设计规范》的「图片资源清单」章节。
+4. **基于图片规划布局**:在「内容大纲」中规划具体页面时,**必须根据图片比例选择布局**。
+ * **竖图 (< 0.8)**:规划为“左右分栏”或“左图右文”布局。
+ * **标准横图 (1.3-1.6)**:规划为“标准插图”或“全屏背景”。
+ * **超宽图 (> 2.0)**:规划为“上下分割”或“页眉/页脚通栏”。
+
---
## 2. 工作流程与交付物
diff --git a/tools/analyze_images.py b/tools/analyze_images.py
index bc75984c..b8234d41 100644
--- a/tools/analyze_images.py
+++ b/tools/analyze_images.py
@@ -113,28 +113,51 @@ def print_results(results):
for cat, imgs in categories.items():
if imgs:
- print(f"\n{cat}: {len(imgs)} images")
+ print(f"\\n{cat}: {len(imgs)} images")
for img in imgs[:5]: # 只显示前5个
print(f" - {img['width']}x{img['height']} (ratio {img['aspect_ratio']:.2f}) - {img['filename'][:35]}...")
if len(imgs) > 5:
print(f" ... and {len(imgs) - 5} more")
# 输出PPT适配建议
- print("\n" + "="*100)
+ print("\\n" + "="*100)
print("PPT Fit Suggestions (16:9 = 1280x720)")
print("="*100)
ppt_width, ppt_height = 1280, 720
ppt_ratio = ppt_width / ppt_height
- print(f"\nStandard PPT canvas: {ppt_width}x{ppt_height} (ratio {ppt_ratio:.2f})")
+ print(f"\\nStandard PPT canvas: {ppt_width}x{ppt_height} (ratio {ppt_ratio:.2f})")
fit_count = 0
for img in results:
if 1.5 <= img['aspect_ratio'] <= 2.0:
fit_count += 1
- print(f"\nImages suitable for full-screen display: {fit_count}")
+ print(f"\\nImages suitable for full-screen display: {fit_count}")
+
+
+def generate_markdown(results):
+ """生成 Markdown 格式的图片资源清单"""
+ print("\\n" + "="*100)
+ print("Markdown Snippet for Strategist (Copy & Paste)")
+ print("="*100)
+ print("\\n## 图片资源清单(自动扫描结果)\\n")
+ print("| 文件名 | 尺寸 | 比例 | 布局建议 | 状态 |")
+ print("|--------|------|------|----------|------|")
+
+ for img in results:
+ # 简化布局建议描述,使其更符合 Strategist 的习惯
+ layout_desc = img['layout_hint']
+ if img['aspect_ratio'] > 2.0:
+ layout_desc += " (适合通栏/分割)"
+ elif img['aspect_ratio'] > 1.2:
+ layout_desc += " (适合全屏/插图)"
+ elif img['aspect_ratio'] < 0.8:
+ layout_desc += " (适合左右分栏)"
+
+ print(f"| {img['filename']} | {img['width']}x{img['height']} | {img['aspect_ratio']:.2f} | {layout_desc} | 已有 |")
+ print("\\n" + "="*100 + "\\n")
def save_csv(results, csv_path):
@@ -172,6 +195,7 @@ def main():
if results:
print_results(results)
+ generate_markdown(results)
# 保存到CSV文件(保存在图片目录的父目录)
parent_dir = os.path.dirname(images_dir)