Analyze the structure of a Markdown article, generate image prompts for each paragraph/section, call the Gemini API to generate images in bulk, and insert them into the document.
Workflow
Phase 1: Analyze the article → Generate prompts
- Read the article - Obtain the article content provided by the user (the currently open file or a specified path)
- Structure analysis - Split paragraphs by H2/H3 headings, extract the core idea of each paragraph
- Generate style instructions - Generate a global STYLE INSTRUCTIONS code block based on the article topic
- Generate prompts - Create an image prompt outline for each paragraph (see references/style-guide.md)
- Display and confirm - Display all prompts as a list and wait for the user to confirm or modify them
Phase 2: Generate images → Insert into the document
- Bulk generation - Call
scripts/generate_image.pyto generate images one by one - Save images - Save to the
obsidian/09image/MMDD-主题名称/directory - Insert into the document - Insert
![[图片路径]]references after each paragraph heading
Phase 1 Detailed Guidance
1. Article structure analysis
After reading the article, split it according to the following rules:
- Use
##(H2) or###(H3) headings as paragraph separators - Ignore the frontmatter (YAML) section
- Ignore auxiliary content such as pure quotes and footnotes
- Extract for each paragraph: the heading, the core viewpoint (1 sentence), and key concepts (3-5 words)
Output format:
## 文章结构分析
| # | 段落标题 | 核心观点 | 关键概念 |
|---|---------|---------|---------|
| 1 | xxx | xxx | A, B, C |
| 2 | xxx | xxx | D, E, F |
2. Generate global style instructions
Before all prompts, a STYLE INSTRUCTIONS block must first be generated. Read references/style-guide.md to obtain the style template.
By default, useStyle 1 (minimalist hand-drawn style), and the user may choose Style 2 (architectural blueprint editorial style).
STYLE INSTRUCTIONS:
- 整体风格: 简约手绘风格 / 建筑蓝图编辑风格
- 色彩方案: 白底为主,黑色线条,[主题点缀色]
- 比例: 16:9 横版
- 分辨率: 2K
- 文字量: 极少,仅保留1-3个核心关键词
- 文字语言: 图片中文字以简体中文为主,专业术语/缩写(如 AI、API、LLM)可保留英文
- 视觉语言: 逻辑图、流程图、概念图
- 一致性: 统一线条粗细、留白比例、排版网格
3. Generate a prompt for each paragraph
Structure of each prompt:
- Style prefix - A general description from STYLE INSTRUCTIONS
- Diagram type - Concept diagram/flowchart/comparison chart/hierarchy diagram/relationship diagram
- Content description - Focus on the core idea of the paragraph, describing the diagram content in narrative language
- Chinese labels - Write Chinese keywords directly (such as "data collection", "intelligent processing"), 1-3 of them
- Chinese-first instruction(required) - Append at the end of each prompt:
ALL text, labels, and annotations in the image MUST be primarily in Chinese (Simplified Chinese, 中文). Use clean Chinese font for main text. Technical terms and abbreviations (e.g. AI, API, LLM, RAG) may remain in English. - Exclusions - "No photography, no realistic elements, no complex gradients"
Display format (waiting for user confirmation):
## 提示词大纲
### 图 1: [段落标题]
- 图表类型: 概念图
- 提示词:
"""
[完整英文提示词]
"""
### 图 2: [段落标题]
...
Key:
- Write the main body of the prompt in English (Gemini understands English prompts better)
- Text labels that need to appear in the image should be written directly in the original Chinese (such as
The central node labeled "AI生产力系统") - Each prompt must include the Chinese-first instruction at the end, ensure the text in the image is primarily in Chinese; technical terms may remain in English
4. Wait for confirmation
After displaying all prompts, ask the user:
- "Are you satisfied with the above prompts? Do you need to modify the description of any image?"
- "After confirmation, batch image generation will begin (N images in total)"
- The user may specify a different style for a particular image or modify its description
Phase 2 Detailed Guide
5. Call the API to generate images
After confirmation, call the script one by one to generate images:
python3 scripts/generate_image.py \
--prompt "提示词内容" \
--output "/Users/ugreen/Documents/obsidian/09image/MMDD-主题名/01-段落名.png" \
--api-key "REMOVED_GEMINI_KEY" \
--api-url "https://generativelanguage.googleapis.com" \
--model "gemini-3-pro-image-preview" \
--aspect-ratio "16:9" \
--resolution "2K"
Notes:
- MMDD takes the current date (e.g., 0206)
- The topic name is extracted from the article's H1 title and simplified into a short name
- Image numbers are two digits (01, 02, 03...)
- After each image is generated, check the script output to confirm success
- If an image fails, record it and continue to the next one, then report the failed items at the end
- Leave a 2-3 second interval between images to avoid API rate limiting
6. Save Path Specification
/Users/ugreen/Documents/obsidian/09image/MMDD-主题简称/
├── 01-段落标题简称.png
├── 02-段落标题简称.png
├── 03-段落标题简称.png
└── ...
7. Insert into Document
Insert the image reference below the corresponding paragraph heading in the article:
## 段落标题
![[09image/MMDD-主题简称/01-段落标题简称.png]]
段落正文内容...
Use the Obsidian wikilink format ![[路径]] to insert.
API Configuration
| Configuration Item | Value |
|---|---|
| API URL | https://generativelanguage.googleapis.com |
| API Key | REMOVED_GEMINI_KEY |
| Model | gemini-3-pro-image-preview |
| Default Aspect Ratio | 16:9 |
| Default Resolution | 2K |
Style Selection
| Style | Features | Applicable Scenarios |
|---|---|---|
| Style 1 (Default) | Minimalist hand-drawn, black lines, white background | General, concept explanation, process description |
| Style 2 | Architectural blueprint/technical journal, refined and minimalist | System architecture, technical analysis, professional content |
The user can choose a global style during the confirmation stage, or specify a different style for an individual image.
Common Usage
| User Says | Action |
|---|---|
| "Add images to this article" | Analyze the currently open article and add images in batch |
| "Batch add images" | Same as above |
| "Add images to the article using Style 2" | Use the architectural blueprint editorial style |
| "Modify the prompt for the 3rd image" | Regenerate the specified image |
| "Regenerate the 2nd image" | Call the API again with the modified prompt |