AI IMAGE GENERATION GUIDE.md
本地来源:seo-llm/raw/seo知识库/TXT整理/seo方法论/seo-knowledge-base/AI-IMAGE-GENERATION-GUIDE.md.txt
# AI 图片生成指南 - Kie.ai API
**目标**: 使用 Kie.ai API 为博客文章生成高质量配图
**优先模型**: Nano Banana (快速、高质量、成本低)
**备用模型**: Midjourney (超高质量、风格多样)
---
## 📋 目录
1. [快速开始](#快速开始)
2. [API Key 配置](#api-key-配置)
3. [Nano Banana 模型使用](#nano-banana-模型使用)
4. [Midjourney 模型使用](#midjourney-模型使用)
5. [实战示例:博客配图生成](#实战示例博客配图生成)
6. [最佳实践](#最佳实践)
7. [故障排查](#故障排查)
---
## 🚀 快速开始
### 为什么使用 AI 生图?
- ✅ **快速高效**: 30秒-2分钟生成高质量图片
- ✅ **成本低廉**: 比购买素材或雇设计师便宜
- ✅ **版权无忧**: AI 生成图片无版权纠纷
- ✅ **风格统一**: 保持品牌视觉一致性
### 模型选择
| 模型 | 速度 | 质量 | 成本 | 适用场景 |
| ---------------------- | ------------ | ---- | ------- | ---------------------------- |
| **Nano Banana** ⭐ | 快 (30秒) | 高 | 20积分 | 博客配图、社交媒体、快速原型 |
| **Nano Banana Edit** | 快 (30秒) | 高 | 20积分 | 图片编辑、风格迁移 |
| **Midjourney Relaxed** | 中 (1-2分钟) | 超高 | 30积分 | 精美配图、封面图、展示图 |
| **Midjourney Fast** | 快 (30秒) | 超高 | 80积分 | 紧急需求、高质量配图 |
| **Midjourney Turbo** | 极快 (15秒) | 超高 | 160积分 | 紧急高质量需求 |
**推荐策略**:
- 日常博客配图 → Nano Banana
- 重要文章封面 → Midjourney Relaxed
- 紧急高质量需求 → Midjourney Fast
---
## 🔑 API Key 配置
### 步骤 1: 获取 API Key
1. 访问 [Kie.ai API Key 管理页面](https://kie.ai/api-key)
2. 登录账号
3. 点击 "生成 API Key"
4. 复制 API Key(格式: `kie_xxxxxxxxxxxxxxxxxxxxxxxx`)
### 步骤 2: 配置环境变量
```bash
# 在项目根目录的 .env 文件中添加
KIE_API_KEY=kie_xxxxxxxxxxxxxxxxxxxxxxxx
```
**安全提醒**:
- ❌ 不要将 API Key 提交到 Git
- ✅ .env 文件已在 .gitignore 中
- ✅ 定期轮换 API Key
### 步骤 3: 验证配置
```bash
# 测试 API Key 是否有效
curl -H "Authorization: Bearer $KIE_API_KEY" \
https://api.kie.ai/api/v1/jobs/createTask
```
---
## 🍌 Nano Banana 模型使用
### 模型特点
- **速度**: 30秒生成
- **质量**: 高质量,适合博客配图
- **成本**: 20积分/图
- **分辨率**: 支持多种比例(1:1, 16:9, 9:16 等)
- **格式**: PNG/JPEG
### 基础用法
#### 1. Text-to-Image (文字生图)
```bash
# Step 1: 创建生成任务
curl -X POST https://api.kie.ai/api/v1/jobs/createTask \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/nano-banana",
"input": {
"prompt": "A futuristic AI laboratory with glowing neural networks, holographic displays showing video upscaling process, sleek modern interior, vibrant blue and purple lighting, photorealistic, 4K",
"image_size": "16:9",
"output_format": "png"
}
}'
# 响应示例
{
"code": 200,
"msg": "success",
"data": {
"taskId": "281e5b0*********************f39b9"
}
}
# Step 2: 查询任务结果
curl -X GET "https://api.kie.ai/api/v1/jobs/recordInfo?taskId=281e5b0*********************f39b9" \
-H "Authorization: Bearer YOUR_API_KEY"
# 成功响应
{
"code": 200,
"msg": "success",
"data": {
"taskId": "281e5b0*********************f39b9",
"state": "success",
"resultJson": "{\"resultUrls\":[\"https://file.aiquickdraw.com/...\"]}"
}
}
```
#### 2. Image-to-Image (图片编辑)
```bash
# 使用 Nano Banana Edit 模型
curl -X POST https://api.kie.ai/api/v1/jobs/createTask \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/nano-banana-edit",
"input": {
"prompt": "Transform this into a vibrant digital art style with neon colors and cyberpunk aesthetic",
"image_urls": ["https://example.com/original-image.jpg"],
"image_size": "16:9",
"output_format": "png"
}
}'
```
### 图片比例选择
| 比例 | 用途 | 尺寸参考 |
| ------ | ----------------- | --------- |
| `1:1` | 社交媒体、缩略图 | 1024x1024 |
| `16:9` | 博客封面、横幅图 | 1920x1080 |
| `9:16` | 手机竖屏、Stories | 1080x1920 |
| `4:3` | 传统显示器 | 1600x1200 |
| `3:2` | 照片打印 | 1800x1200 |
**博客配图推荐**: `16:9` (最常用)
### Node.js 代码示例
```javascript
// scripts/generate-nano-banana-image.js
const axios = require('axios');
const KIE_API_KEY = process.env.KIE_API_KEY;
const API_BASE_URL = 'https://api.kie.ai/api/v1/jobs';
async function generateImage(prompt, imageSize = '16:9') {
try {
// Step 1: 创建任务
const createResponse = await axios.post(
`${API_BASE_URL}/createTask`,
{
model: 'google/nano-banana',
input: {
prompt,
image_size: imageSize,
output_format: 'png',
},
},
{
headers: {
Authorization: `Bearer ${KIE_API_KEY}`,
'Content-Type': 'application/json',
},
}
);
const taskId = createResponse.data.data.taskId;
console.log(`✅ 任务创建成功,Task ID: ${taskId}`);
// Step 2: 轮询查询结果
let attempts = 0;
const maxAttempts = 60; // 最多等待 60 * 5 = 300秒 (5分钟)
while (attempts < maxAttempts) {
await new Promise((resolve) => setTimeout(resolve, 5000)); // 等待 5 秒
const resultResponse = await axios.get(
`${API_BASE_URL}/recordInfo?taskId=${taskId}`,
{
headers: {
Authorization: `Bearer ${KIE_API_KEY}`,
},
}
);
const { state, resultJson } = resultResponse.data.data;
if (state === 'success') {
const result = JSON.parse(resultJson);
console.log(`🎉 图片生成成功!`);
console.log(`📷 图片地址: ${result.resultUrls[0]}`);
return result.resultUrls[0];
} else if (state === 'fail') {
throw new Error('图片生成失败');
}
attempts++;
console.log(`⏳ 等待中... (${attempts}/${maxAttempts})`);
}
throw new Error('任务超时');
} catch (error) {
console.error('❌ 错误:', error.message);
throw error;
}
}
// 使用示例
const prompt =
'A modern AI-powered video upscaling interface, sleek dark theme, glowing blue accents, before/after comparison sliders, futuristic tech aesthetic, professional software UI, 4K quality';
generateImage(prompt, '16:9').then((imageUrl) => {
console.log('✅ 生成完成,图片 URL:', imageUrl);
});
```
**运行**:
```bash
node scripts/generate-nano-banana-image.js
```
---
## 🎨 Midjourney 模型使用
### 模型特点
- **速度**: Relaxed (1-2分钟), Fast (30秒), Turbo (15秒)
- **质量**: 超高质量,艺术感强
- **成本**: Relaxed (30积分), Fast (80积分), Turbo (160积分)
- **特色**: 支持风格参考、图片编辑、视频生成
### 基础用法
#### 1. Text-to-Image
```bash
curl -X POST https://api.kie.ai/api/v1/mj/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"taskType": "mj_txt2img",
"prompt": "A cinematic shot of advanced AI technology upscaling vintage home videos, holographic displays showing before/after comparison, warm nostalgic lighting mixed with futuristic elements, photorealistic, 8K --ar 16:9 --v 7",
"speed": "relaxed",
"aspectRatio": "16:9",
"version": "7"
}'
```
#### 2. Image-to-Image
```bash
curl -X POST https://api.kie.ai/api/v1/mj/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"taskType": "mj_img2img",
"prompt": "Transform into a vibrant digital illustration with sci-fi elements",
"fileUrls": ["https://example.com/source-image.jpg"],
"speed": "relaxed",
"aspectRatio": "16:9",
"version": "7"
}'
```
#### 3. 查询任务结果
```bash
curl -X GET "https://api.kie.ai/api/v1/mj/record-info?taskId=mj_task_abcdef123456" \
-H "Authorization: Bearer YOUR_API_KEY"
# 成功响应(通常生成 4 张图片)
{
"code": 200,
"data": {
"successFlag": 1,
"resultInfoJson": {
"resultUrls": [
{ "resultUrl": "https://tempfile.aiquickdraw.com/v/image_0.jpeg" },
{ "resultUrl": "https://tempfile.aiquickdraw.com/v/image_1.jpeg" },
{ "resultUrl": "https://tempfile.aiquickdraw.com/v/image_2.jpeg" },
{ "resultUrl": "https://tempfile.aiquickdraw.com/v/image_3.jpeg" }
]
}
}
}
```
#### 4. 放大图片 (Upscale)
```bash
# 选择 4 张图片中的一张进行放大(imageIndex: 0-3)
curl -X POST https://api.kie.ai/api/v1/mj/generateUpscale \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"taskId": "mj_task_abcdef123456",
"imageIndex": 0
}'
```
### Midjourney Prompt 技巧
#### 基础结构
```
[主体] + [风格] + [细节] + [参数]
```
#### 示例 Prompts
**博客封面**:
```
A professional tech blog header featuring AI-powered video restoration, split-screen showing old grainy footage transforming into crystal-clear 4K, modern minimalist design, cool blue gradient background, glass morphism UI elements --ar 16:9 --v 7 --stylize 100
```
**教程配图**:
```
Step-by-step tutorial illustration of AI upscaling workflow, clean infographic style, numbered steps with icons, arrows showing process flow, vibrant gradient accents, white background, professional and easy to understand --ar 16:9 --v 7
```
**产品展示**:
```
Sleek product showcase of AI video upscaling software interface on MacBook Pro, dark mode UI with neon blue accents, before/after video comparison playing, modern office desk setup, soft studio lighting, photorealistic --ar 16:9 --v 7 --stylize 200
```
#### Midjourney 参数说明
| 参数 | 说明 | 范围 | 推荐值 |
| ----------- | ---------- | ------------------ | ---------------------- |
| `--ar` | 宽高比 | 1:1, 16:9, 9:16 等 | 16:9 (博客) |
| `--v` | 模型版本 | 5.1, 6, 7 | 7 (最新) |
| `--stylize` | 风格化程度 | 0-1000 | 100 (自然), 500 (艺术) |
| `--chaos` | 多样性 | 0-100 | 10 (稳定), 50 (多样) |
| `--weird` | 怪异度 | 0-3000 | 0 (正常), 500 (创意) |
---
## 💡 实战示例:博客配图生成
### 场景 1: 为 "AI 视频放大教程" 生成封面图
**需求**:
- 16:9 横幅图
- 展示 AI 技术感
- 体现视频质量提升
**Nano Banana 方案** (快速、性价比高):
```javascript
// scripts/generate-blog-cover.js
const prompt = `
A modern AI video upscaling interface, split-screen comparison showing blurry old video on left transforming into sharp 4K quality on right,
sleek dark software UI with glowing blue progress bar,
futuristic holographic elements, professional tech aesthetic,
cinematic lighting, photorealistic, 8K quality
`;
generateImage(prompt, '16:9');
```
**Midjourney 方案** (高质量):
```bash
curl -X POST https://api.kie.ai/api/v1/mj/generate \
-H "Authorization: Bearer $KIE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"taskType": "mj_txt2img",
"prompt": "Cinematic AI video upscaling demonstration, vintage home movie transforming into crystal-clear 4K, holographic interface overlays, warm nostalgic colors mixed with futuristic blue tech elements, emotional and technological, photorealistic --ar 16:9 --v 7 --stylize 200",
"speed": "relaxed",
"aspectRatio": "16:9",
"version": "7",
"stylization": 200
}'
```
### 场景 2: 为 "ComfyUI 工作流指南" 生成配图
**需求**:
- 清晰的流程图
- 专业技术风格
- 易于理解
**Prompt**:
```
Clean technical diagram of ComfyUI workflow for video upscaling,
node-based visual programming interface,
connected blocks showing input → processing → output flow,
minimalist dark theme with neon green connection lines,
professional software documentation style,
highly readable, infographic quality --ar 16:9 --v 7
```
### 场景 3: 批量生成系列文章配图
```javascript
// scripts/batch-generate-images.js
const blogTopics = [
{
title: 'Ultimate Upscaling Guide 2026',
prompt:
'Professional AI upscaling software interface showcasing various enhancement options, before/after quality comparison sliders, modern dark UI design --ar 16:9',
},
{
title: 'Low VRAM Workflow',
prompt:
'Computer hardware diagram highlighting GPU memory optimization, visual representation of efficient resource usage, technical illustration style --ar 16:9',
},
{
title: '8GB VRAM Secrets',
prompt:
'Infographic showing memory management tips for AI video processing, clean layout with icons and statistics, professional tech aesthetic --ar 16:9',
},
];
async function batchGenerate() {
for (const topic of blogTopics) {
console.log(`\n🎨 生成配图: ${topic.title}`);
const imageUrl = await generateImage(topic.prompt);
console.log(`✅ 完成: ${imageUrl}\n`);
// 等待 5 秒避免 API 限流
await new Promise((resolve) => setTimeout(resolve, 5000));
}
}
batchGenerate();
```
---
## 📐 最佳实践
### 1. Prompt 编写技巧
#### ✅ 好的 Prompt
```
A modern AI-powered video editing interface displaying real-time upscaling progress,
sleek dark theme with blue accent colors,
split-screen comparison showing SD to 4K transformation,
professional software UI design,
clean and minimalist,
photorealistic rendering,
16:9 aspect ratio
```
**特点**:
- 具体描述主体
- 明确风格和色调
- 包含技术细节
- 指定质量要求
#### ❌ 差的 Prompt
```
video upscaling software
```
**问题**:
- 过于简单
- 缺少细节
- 没有风格指导
- 结果不可预测
### 2. 图片比例选择
| 用途 | 推荐比例 | 说明 |
| -------- | ---------- | -------------------------- |
| 博客封面 | 16:9 | 标准横幅,适配大多数网站 |
| 社交媒体 | 1:1 | Instagram, Twitter 缩略图 |
| Stories | 9:16 | Instagram/Facebook Stories |
| 打印海报 | 3:2 或 4:3 | 传统打印比例 |
### 3. 成本优化
**策略 1: 优先使用 Nano Banana**
- 日常配图用 Nano Banana (20积分)
- 重要封面用 Midjourney Relaxed (30积分)
- 紧急情况用 Midjourney Fast (80积分)
**策略 2: 批量生成**
```javascript
// 一次生成多张,选择最佳
const response = await axios.post(API_URL, {
model: 'google/nano-banana',
input: {
prompt: yourPrompt,
num_images: 4, // Nano Banana 支持多图
},
});
```
**策略 3: 复用和编辑**
- 保存满意的图片作为参考
- 使用 Image-to-Image 进行微调
- 建立 Prompt 模板库
### 4. 图片文件管理
```bash
# 下载并保存图片的脚本
# scripts/download-generated-image.js
const fs = require('fs');
const path = require('path');
const https = require('https');
async function downloadImage(url, filename) {
const filepath = path.join(__dirname, '../public/blog-images', filename);
return new Promise((resolve, reject) => {
https.get(url, (response) => {
const fileStream = fs.createWriteStream(filepath);
response.pipe(fileStream);
fileStream.on('finish', () => {
fileStream.close();
console.log(`✅ 图片已保存: ${filepath}`);
resolve(filepath);
});
fileStream.on('error', reject);
});
});
}
// 使用示例
downloadImage(
'https://file.aiquickdraw.com/custom-page/akr/section-images/1756223371764w82dsmi4.png',
'tutorial-ultimate-upscaling-guide-2026.png'
);
```
### 5. 图片优化
生成后的图片建议进行优化:
```bash
# 使用 sharp 库优化图片
npm install sharp
# scripts/optimize-image.js
const sharp = require('sharp');
async function optimizeImage(inputPath, outputPath) {
await sharp(inputPath)
.resize(1920, 1080, { fit: 'inside' }) // 限制最大尺寸
.webp({ quality: 85 }) // 转换为 WebP 格式
.toFile(outputPath);
console.log(`✅ 图片已优化: ${outputPath}`);
}
optimizeImage(
'public/blog-images/original.png',
'public/blog-images/optimized.webp'
);
```
---
## 🔧 故障排查
### 问题 1: API Key 无效
**错误信息**:
```json
{
"code": 401,
"msg": "Unauthorized - Authentication credentials are missing or invalid"
}
```
**解决方法**:
1. 检查 API Key 是否正确复制
2. 确认 Authorization header 格式: `Bearer YOUR_API_KEY`
3. 访问 [API Key 管理页面](https://kie.ai/api-key) 重新生成
### 问题 2: 任务一直处于 waiting 状态
**原因**:
- 服务器负载高
- 任务排队中
**解决方法**:
1. 延长轮询等待时间(最多 5 分钟)
2. 使用 callback URL 代替轮询
3. 选择 Fast/Turbo 速度(Midjourney)
### 问题 3: 生成的图片质量不理想
**优化方法**:
1. **优化 Prompt**:
- 增加更多细节描述
- 指定风格和质量关键词(photorealistic, 4K, professional 等)
- 参考优秀 Prompt 示例
2. **调整参数**:
```json
{
"stylization": 200, // 增加艺术感
"variety": 10, // 保持一致性
"version": "7" // 使用最新版本
}
```
3. **切换模型**:
- Nano Banana 不满意 → 试试 Midjourney
- 需要更艺术化 → 提高 stylization 值
### 问题 4: 积分不足
**错误信息**:
```json
{
"code": 402,
"msg": "Insufficient Credits"
}
```
**解决方法**:
1. 登录 [Kie.ai](https://kie.ai) 充值积分
2. 优化使用策略:优先使用 Nano Banana 节省积分
3. 批量生成时控制数量
### 问题 5: 图片 URL 过期
**说明**:
- Nano Banana 图片保留 15 天
- Midjourney 图片保留 15 天
**解决方法**:
```javascript
// 生成后立即下载保存到本地
const imageUrl = await generateImage(prompt);
await downloadImage(imageUrl, 'blog-cover.png');
```
---
## 📚 相关资源
- **API 文档**: [Kie.ai API Docs](https://kie.ai/docs)
- **API Key 管理**: [https://kie.ai/api-key](https://kie.ai/api-key)
- **Prompt 参考**: [Midjourney Prompt Guide](https://docs.midjourney.com/docs/prompts)
- **本项目配图指南**: [GENERATE-IMAGES-GUIDE.md](GENERATE-IMAGES-GUIDE.md)
---
## 🎯 快速命令参考
### Nano Banana - Text-to-Image
```bash
curl -X POST https://api.kie.ai/api/v1/jobs/createTask \
-H "Authorization: Bearer $KIE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/nano-banana",
"input": {
"prompt": "YOUR_PROMPT_HERE",
"image_size": "16:9",
"output_format": "png"
}
}'
```
### Midjourney - Text-to-Image
```bash
curl -X POST https://api.kie.ai/api/v1/mj/generate \
-H "Authorization: Bearer $KIE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"taskType": "mj_txt2img",
"prompt": "YOUR_PROMPT_HERE --ar 16:9 --v 7",
"speed": "relaxed",
"aspectRatio": "16:9",
"version": "7"
}'
```
### 查询任务状态
```bash
# Nano Banana
curl "https://api.kie.ai/api/v1/jobs/recordInfo?taskId=YOUR_TASK_ID" \
-H "Authorization: Bearer $KIE_API_KEY"
# Midjourney
curl "https://api.kie.ai/api/v1/mj/record-info?taskId=YOUR_TASK_ID" \
-H "Authorization: Bearer $KIE_API_KEY"
```
---
**版本**: 1.0.0
**更新日期**: 2026-01-23
**维护**: SEO Team
本文档为站内渲染。原始文件本地路径:saas/source/seo-llm/raw-seo知识库-TXT整理-seo方法论-seo-knowledge-base-AI-IMAGE-GENERATI-7952d2.txt(仅本地保留,不入库不部署)