article-illustration-generator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseArticle Illustration Generator
文章插图生成器
This skill automatically generates relevant illustrations for a text article using the Gemini Image API and converts it into a visually appealing HTML file.
本Skill使用Gemini Image API自动为文本文章生成相关插图,并将其转换为视觉吸引力强的HTML文件。
Workflow
工作流程
-
API Key Check:
- First, check if the GOOGLE_API_KEY environment variable is set.
- If not set, use the AskUserQuestion tool to ask the user if they have configured their API key.
- If the user hasn't configured it, ask them to provide their Google API key.
- Store the API key for use in the script execution.
-
Input Analysis:
- Read the user's article text.
- Split the text into logical sections (paragraphs).
- Identify key scenes for illustration (aim for 1 image every 2-3 paragraphs).
-
Image Generation:
- For each identified scene, generate a descriptive prompt based on the text context.
- Use the SDK to generate images.
google.genai - Model: (default, or user specified).
gemini-2.5-flash-image - Config: Use or
aspect_ratio="16:9"for article images.4:3
-
HTML Construction:
- Use the HTML template provided in ("故都的秋" style).
assets/template.html - Insert the text and generated images (saved locally) into the HTML structure.
- Use the HTML template provided in
-
API密钥检查:
- 首先,检查是否已设置GOOGLE_API_KEY环境变量。
- 如果未设置,使用AskUserQuestion工具询问用户是否已配置API密钥。
- 如果用户尚未配置,请求他们提供Google API密钥。
- 存储API密钥以供脚本执行使用。
-
输入分析:
- 读取用户的文章文本。
- 将文本拆分为逻辑段落。
- 确定适合插图的关键场景(目标为每2-3段配1张图片)。
-
图像生成:
- 为每个确定的场景,基于文本上下文生成描述性提示词。
- 使用SDK生成图像。
google.genai - 模型: (默认,或用户指定)。
gemini-2.5-flash-image - 配置: 文章图片使用或
aspect_ratio="16:9"比例。4:3
-
HTML构建:
- 使用中提供的HTML模板(“故都的秋”风格)。
assets/template.html - 将文本和生成的图像(保存到本地)插入到HTML结构中。
- 使用
Resources
资源
This skill includes reference files in the directory:
references/- : The HTML/CSS template with serif fonts and clean layout. Use this as the base for the output file.
references/template.html - : Detailed documentation for the Nano Banana Pro (Gemini 3 Pro Image) API, which can be used for advanced image generation needs.
references/api_guide.md - : A Python script template containing the API calling logic.
references/script_template.py
本Skill在目录中包含参考文件:
references/- : 带有衬线字体和简洁布局的HTML/CSS模板,用作输出文件的基础。
references/template.html - : Nano Banana Pro(Gemini 3 Pro Image)API的详细文档,可用于高级图像生成需求。
references/api_guide.md - : 包含API调用逻辑的Python脚本模板。
references/script_template.py
Usage Guide
使用指南
When invoked, the agent should:
-
Check API Key Configuration:
- Use Bash to check if GOOGLE_API_KEY environment variable is set: (Linux/Mac) or
echo $GOOGLE_API_KEY(Windows).echo %GOOGLE_API_KEY% - If empty or not set, use AskUserQuestion to ask: "您是否已经配置了 Google API Key?"
- Option 1: "是,已配置为环境变量" - Proceed with the script.
- Option 2: "否,我需要提供 API Key" - Ask for the API key and pass it as a command-line argument to the script.
- If the user provides an API key, store it temporarily for this execution.
- Use Bash to check if GOOGLE_API_KEY environment variable is set:
-
Read the target article provided by the user.
-
Plan the image insertion points.
-
Execute the Python script () with appropriate parameters:
scripts/article_to_html.py- If API key was provided by user:
python scripts/article_to_html.py <article_file> <api_key> - If using environment variable:
python scripts/article_to_html.py <article_file> - Optional parameters: ,
--images N,--model MODEL,--ratio RATIO--size SIZE
- If API key was provided by user:
-
Verify the result and inform the user of the output location.
调用本Agent时,应执行以下步骤:
-
检查API密钥配置:
- 使用Bash检查是否已设置GOOGLE_API_KEY环境变量:(Linux/Mac)或
echo $GOOGLE_API_KEY(Windows)。echo %GOOGLE_API_KEY% - 如果为空或未设置,使用AskUserQuestion询问:“您是否已经配置了 Google API Key?”
- 选项1:“是,已配置为环境变量” - 继续执行脚本。
- 选项2:“否,我需要提供 API Key” - 请求用户提供API密钥,并将其作为命令行参数传递给脚本。
- 如果用户提供了API密钥,临时存储该密钥以供本次执行使用。
- 使用Bash检查是否已设置GOOGLE_API_KEY环境变量:
-
读取用户提供的目标文章。
-
规划图像插入位置。
-
使用适当的参数执行Python脚本():
scripts/article_to_html.py- 如果用户提供了API密钥:
python scripts/article_to_html.py <article_file> <api_key> - 如果使用环境变量:
python scripts/article_to_html.py <article_file> - 可选参数:,
--images N,--model MODEL,--ratio RATIO--size SIZE
- 如果用户提供了API密钥:
-
验证结果并告知用户输出文件的位置。