关于 image-gen
image-gen 是使用 Gemini Native Image Generation 生成和编辑网站图片的 Skill,涵盖模型选择、图片处理流程、API 用法及已知限制。
主要功能
- 01根据文本生成图片
- 02编辑图片、风格和颜色
- 03调整宽高比并扩展图片
- 04使用多张参考图片
- 05按分辨率和任务选择模型
- 06说明 API 注意事项与限制
适用场景
- 01制作定制网站图片
- 02调整现有图片以适配版式
- 03生成带文字的信息图
- 04保持多张图片的视觉风格一致
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ jezweb/ claude-skills --skill image-gen安装后在 Claude Code 中输入/image-gen确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
README.md.claude-plugin/plugin.jsonagents/image-prompter.mdreferences/editing.mdintegration.mdlocal-imagery.mdprompting.mdwebsite-images.mdrules/image-gen.md详细介绍
图像生成技能
使用 Gemini 原生图像生成来生成和编辑网站图像。
⚠️ 重要:必须迁移 SDK
重要:@google/generative-ai 软件包已于 2025 年 11 月 30 日弃用。所有新项目必须使用 @google/genai。
必须迁移:
// ❌ OLD (deprecated, support ended Nov 30, 2025)
import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(API_KEY);
// ✅ NEW (required)
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: API_KEY });
模型
| 模型 | ID | 状态 | 最适合用途 |
|---|---|---|---|
| Gemini 3 Pro Image | gemini-3-pro-image-preview | 预览版(2025 年 11 月 20 日) | 4K、复杂提示词、文本 |
| Gemini 2.5 Flash Image | gemini-2.5-flash-image | 正式可用(2025 年 10 月 2 日) | 快速迭代、通用用途 |
| Imagen 4.0 | imagen-4.0-generate-001 | 正式可用(2025 年 8 月 14 日) | 替代平台 |
已弃用的模型(请勿使用):
gemini-2.0-flash-exp-image-generation- 已于 2025 年 11 月 11 日停用gemini-2.0-flash-preview-image-generation- 已于 2025 年 11 月 11 日停用gemini-2.5-flash-image-preview- 计划于 2026 年 1 月 15 日停用
功能
| 功能 | 支持 |
|---|---|
| 根据文本生成 | ✅ |
| 编辑现有图像 | ✅ |
| 更改宽高比 | ✅ |
| 加宽/扩展图像 | ✅ |
| 风格迁移 | ✅ |
| 更改颜色 | ✅ |
| 添加/移除元素 | ✅ |
| 图像中的文本 | ✅(清晰可读!) |
| 多张参考图像 | ✅(最多 14 张:最多 5 张人物、9 张物体) |
| 4K 分辨率 | ✅(仅限 Pro) |
注意:超过 5 张人物参考图像会导致角色一致性不可预测。为获得可靠结果,人物图像请勿超过 5 张。
宽高比
1:1 | 2:3 | 3:2 | 3:4 | 4:3
4:5 | 5:4 | 9:16 | 16:9 | 21:9
分辨率(仅限 Pro)
| 尺寸 | 1:1 | 16:9 | 4:3 |
|---|---|---|---|
| 1K | 1024x1024 | 1376x768 | 1184x880 |
| 2K | 2048x2048 | 2752x1536 | 2368x1760 |
| 4K | 4096x4096 | 5504x3072 | 4736x3520 |
快速开始
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
// Generate new image
const response = await ai.models.generateContent({
model: "gemini-2.5-flash-image",
contents: "A professional plumber in hi-vis working in modern Australian home",
config: {
responseModalities: ["TEXT", "IMAGE"], // BOTH required - cannot use ["IMAGE"] alone
imageGenerationConfig: {
aspectRatio: "16:9",
},
},
});
// Extract image
for (const part of response.candidates[0].content.parts) {
if (part.inlineData) {
const buffer = Buffer.from(part.inlineData.data, "base64");
fs.writeFileSync("hero.png", buffer);
}
}
重要:responseModalities 必须同时包含 ["TEXT", "IMAGE"]。仅使用 ["IMAGE"] 可能会失败或产生意外结果。
模型选择
| 需求 | 使用 |
|---|---|
| 快速迭代 | Gemini 2.5 Flash Image |
| 4K 分辨率 | Gemini 3 Pro Image Preview |
| 图像中的文本 | Gemini 3 Pro(4K 下文本可读率为 94%) |
| 简单编辑 | Gemini 2.5 Flash Image |
| 复杂构图 | Gemini 3 Pro Image Preview |
| 信息图/图表 | Gemini 3 Pro Image Preview |
文本渲染基准(4K 分辨率):
- Gemini 3 Pro Image:94% 文本清晰可读
- DALL-E 3:78% 文本清晰可读
- Midjourney:仅生成装饰性伪文本
适用场景
以下情况请使用 Gemini Image Gen:
- 素材照片不符合品牌/场景需求
- 需要澳大利亚特色图像
- 需要在图像中添加文本(信息图、图表)
- 需要多张图像保持风格一致
- 需要编辑/修改现有图像
- 客户没有其作品的照片
以下情况请勿使用:
- 客户有优质的实际作品照片
- 需要真实的团队照片(请先讨论)
- 产品照片(请使用真实产品)
- 存在法律/合规方面的顾虑
预防已知问题
此技能可预防 5 个已记录的问题:
问题 #1:分辨率参数区分大小写
错误:请求失败,并提示参数无效
来源:Google AI 图像生成文档
原因:分辨率值区分大小写,必须使用大写字母“K”。
预防措施:始终使用 "4K"、"2K"、"1K"——切勿使用小写形式 "4k"。
// ❌ WRONG - causes request failure
config: { imageGenerationConfig: { resolution: "4k" } }
// ✅ CORRECT - uppercase required
config: { imageGenerationConfig: { resolution: "4K" } }
问题 #2:可能会忽略宽高比(2025 年 9 月起)
错误:请求 16:9 或其他宽高比,却返回 1:1 正方形图像 来源:Google 支持讨论帖 原因:2025 年 9 月的后端更新影响了 Gemini 2.5 Flash Image 模型对宽高比的处理。 预防措施:使用 Gemini 3 Pro Image Preview 可靠地控制宽高比,或者先生成 1:1 图像,再通过多轮编辑扩展图像。
// May ignore aspectRatio on Gemini 2.5 Flash Image
model: "gemini-2.5-flash-image",
config: { imageGenerationConfig: { aspectRatio: "16:9" } }
// More reliable for aspect ratio control
model: "gemini-3-pro-image-preview",
config: { imageGenerationConfig: { aspectRatio: "16:9" } }
状态:Google 已确认正在修复(2025 年 9 月)。
问题 #3:超过 5 张人物参考图
错误:生成图像中的角色一致性难以预测 来源:Google AI 图像生成文档 原因:Gemini 3 Pro Image 最多支持 14 张参考图,但为了保持角色一致性,其中人物图最多只能有 5 张。 预防措施:人物图限制为 5 张或更少。其余名额(最多共 14 张)可用于物体或场景。
// ❌ WRONG - 7 human images exceeds limit
const humanImages = [img1, img2, img3, img4, img5, img6, img7];
const prompt = [
{ text: "Generate consistent characters" },
...humanImages.map(img => ({ inlineData: { data: img, mimeType: "image/png" }})),
];
// ✅ CORRECT - max 5 human images
const humanImages = images.slice(0, 5); // Limit to 5
const objectImages = images.slice(5, 14); // Up to 9 more for objects
const prompt = [
{ text: "Generate consistent characters" },
...humanImages.map(img => ({ inlineData: { data: img, mimeType: "image/png" }})),
...objectImages.map(img => ({ inlineData: { data: img, mimeType: "image/png" }})),
];
问题 #4:无法停用 SynthID 水印
错误:不适用(已记录的限制) 来源:Google AI 图像生成文档 原因:所有生成的图像都会自动添加 SynthID 水印,用于追踪内容真实性。 预防措施:商业用途请注意此限制。开发者无法停用水印。
问题 #5:Google Search Grounding 不包含图像结果
错误:生成的图像不会反映视觉搜索结果,只会反映文本 来源:Google AI 图像生成文档 原因:使用 Google Search 工具生成图像时,“基于图像的搜索结果不会传递给生成模型”。 预防措施:视觉输出仅参考基于文本的搜索结果。不要期望模型会参考搜索结果中的图像。
// Google Search tool enabled
const response = await ai.models.generateContent({
model: "gemini-3-pro-image-preview",
contents: "Generate image of latest iPhone design",
tools: [{ googleSearch: {} }],
config: { responseModalities: ["TEXT", "IMAGE"] },
});
// Result: Only text search results used, not image results from web search
定价
当前定价(截至 2025 年 11 月):
- Gemini 2.5 Flash Image:每张图像约 0.008 美元
- 输入:每张图像 258 个 token
- 输出:每张图像 1290 个 token
- 费率:每 100 万个输出 token 收费 30.00 美元
注意:generateImages API(Imagen 模型)不会在响应中返回 usageMetadata。请根据上述定价手动追踪费用。
来源:Google 开发者博客 - Gemini 2.5 Flash Image
参考文件
references/prompting.md- 有效的提示词模式references/website-images.md- 主视觉、服务和背景模板references/editing.md- 多轮编辑模式references/local-imagery.md- 澳大利亚相关细节references/integration.md- API 代码示例
上次验证时间:2026-01-21 | 技能版本:2.0.0 | 变更:添加 SDK 迁移通知(重要);更新为当前模型名称(gemini-3-pro-image-preview、gemini-2.5-flash-image);添加 5 个已知问题(分辨率区分大小写、宽高比错误、参考图限制、SynthID 水印、Google Search grounding);添加定价部分;添加文本渲染基准测试。