image-generation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImage Generation Skill
AI图像生成技能
This skill guides the implementation of image generation functionality using the z-ai-web-dev-sdk package and CLI tool, enabling creation of high-quality images from text descriptions.
本技能指导如何使用z-ai-web-dev-sdk包和CLI工具实现图像生成功能,支持根据文本描述创建高质量图像。
Skills Path
技能路径
Skill Location:
{project_path}/skills/image-generationthis skill is located at above path in your project.
Reference Scripts: Example test scripts are available in the directory for quick testing and reference. See for a working example.
{Skill Location}/scripts/{Skill Location}/scripts/image-generation.ts技能位置:
{project_path}/skills/image-generation本技能位于项目中的上述路径。
参考脚本:目录下提供了示例测试脚本,可用于快速测试和参考。为可运行的示例文件。
{Skill Location}/scripts/{Skill Location}/scripts/image-generation.tsOverview
概述
Image Generation allows you to build applications that create visual content from text prompts using AI models, enabling creative workflows, design automation, and visual content production.
IMPORTANT: z-ai-web-dev-sdk MUST be used in backend code only. Never use it in client-side code.
图像生成功能允许你构建基于AI模型的应用,通过文本提示创建视觉内容,支持创意工作流、设计自动化和视觉内容生产。
重要提示:z-ai-web-dev-sdk仅能在后端代码中使用,绝不能在客户端代码中使用。
Prerequisites
前提条件
The z-ai-web-dev-sdk package is already installed. Import it as shown in the examples below.
z-ai-web-dev-sdk包已预先安装,可按照下方示例导入使用。
Basic Image Generation
基础图像生成
Simple Image Creation
简单图像创建
javascript
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
async function generateImage(prompt, outputPath) {
const zai = await ZAI.create();
const response = await zai.images.generations.create({
prompt: prompt,
size: '1024x1024'
});
const imageBase64 = response.data[0].base64;
// Save image
const buffer = Buffer.from(imageBase64, 'base64');
fs.writeFileSync(outputPath, buffer);
console.log(`Image saved to ${outputPath}`);
return outputPath;
}
// Usage
await generateImage(
'A cute cat playing in the garden',
'./cat_image.png'
);javascript
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
async function generateImage(prompt, outputPath) {
const zai = await ZAI.create();
const response = await zai.images.generations.create({
prompt: prompt,
size: '1024x1024'
});
const imageBase64 = response.data[0].base64;
// 保存图像
const buffer = Buffer.from(imageBase64, 'base64');
fs.writeFileSync(outputPath, buffer);
console.log(`图像已保存至 ${outputPath}`);
return outputPath;
}
// 使用示例
await generateImage(
'一只在花园里玩耍的可爱猫咪',
'./cat_image.png'
);Multiple Image Sizes
多尺寸图像生成
javascript
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
// Supported sizes
const SUPPORTED_SIZES = [
'1024x1024', // Square
'768x1344', // Portrait
'864x1152', // Portrait
'1344x768', // Landscape
'1152x864', // Landscape
'1440x720', // Wide landscape
'720x1440' // Tall portrait
];
async function generateImageWithSize(prompt, size, outputPath) {
if (!SUPPORTED_SIZES.includes(size)) {
throw new Error(`Unsupported size: ${size}. Use one of: ${SUPPORTED_SIZES.join(', ')}`);
}
const zai = await ZAI.create();
const response = await zai.images.generations.create({
prompt: prompt,
size: size
});
const imageBase64 = response.data[0].base64;
const buffer = Buffer.from(imageBase64, 'base64');
fs.writeFileSync(outputPath, buffer);
return {
path: outputPath,
size: size,
fileSize: buffer.length
};
}
// Usage - Different sizes
await generateImageWithSize(
'A beautiful landscape',
'1344x768',
'./landscape.png'
);
await generateImageWithSize(
'A portrait of a person',
'768x1344',
'./portrait.png'
);javascript
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
// 支持的尺寸
const SUPPORTED_SIZES = [
'1024x1024', // 正方形
'768x1344', // 竖版
'864x1152', // 竖版
'1344x768', // 横版
'1152x864', // 横版
'1440x720', // 宽幅横版
'720x1440' // 长竖版
];
async function generateImageWithSize(prompt, size, outputPath) {
if (!SUPPORTED_SIZES.includes(size)) {
throw new Error(`不支持的尺寸:${size}。请使用以下尺寸之一:${SUPPORTED_SIZES.join(', ')}`);
}
const zai = await ZAI.create();
const response = await zai.images.generations.create({
prompt: prompt,
size: size
});
const imageBase64 = response.data[0].base64;
const buffer = Buffer.from(imageBase64, 'base64');
fs.writeFileSync(outputPath, buffer);
return {
path: outputPath,
size: size,
fileSize: buffer.length
};
}
// 使用示例 - 不同尺寸
await generateImageWithSize(
'一幅美丽的风景画',
'1344x768',
'./landscape.png'
);
await generateImageWithSize(
'一幅人物肖像',
'768x1344',
'./portrait.png'
);CLI Tool Usage
CLI工具使用
The z-ai CLI tool provides a convenient way to generate images directly from the command line.
z-ai CLI工具提供了从命令行直接生成图像的便捷方式。
Basic CLI Usage
基础CLI使用
bash
undefinedbash
undefinedGenerate image with full options
完整参数生成图像
z-ai image --prompt "A beautiful landscape" --output "./image.png"
z-ai image --prompt "一幅美丽的风景画" --output "./image.png"
Short form
简写形式
z-ai image -p "A cute cat" -o "./cat.png"
z-ai image -p "一只可爱的猫咪" -o "./cat.png"
Specify size
指定尺寸
z-ai image -p "A sunset" -o "./sunset.png" -s 1344x768
z-ai image -p "日落景象" -o "./sunset.png" -s 1344x768
Portrait orientation
竖版肖像
z-ai image -p "A portrait" -o "./portrait.png" -s 768x1344
undefinedz-ai image -p "一幅肖像" -o "./portrait.png" -s 768x1344
undefinedCLI Use Cases
CLI使用场景
bash
undefinedbash
undefinedWebsite hero image
网站首屏横幅
z-ai image -p "Modern tech office with diverse team collaborating" -o "./hero.png" -s 1440x720
z-ai image -p "多元化团队协作的现代科技办公室" -o "./hero.png" -s 1440x720
Product image
产品图片
z-ai image -p "Sleek smartphone on minimalist desk, professional product photography" -o "./product.png" -s 1024x1024
z-ai image -p "极简桌面上的时尚智能手机,专业产品摄影风格" -o "./product.png" -s 1024x1024
Blog post illustration
博客文章插图
z-ai image -p "Abstract visualization of data flowing through networks" -o "./blog_header.png" -s 1344x768
z-ai image -p "数据在网络中流动的抽象可视化图" -o "./blog_header.png" -s 1344x768
Social media content
社交媒体内容
z-ai image -p "Vibrant illustration of community connection" -o "./social.png" -s 1024x1024
z-ai image -p "充满活力的社区连接插画" -o "./social.png" -s 1024x1024
Website favicon/logo
网站图标/Logo
z-ai image -p "Simple geometric logo with blue gradient, minimal design" -o "./logo.png" -s 1024x1024
z-ai image -p "带有蓝色渐变的简约几何Logo,极简设计" -o "./logo.png" -s 1024x1024
Background pattern
背景图案
z-ai image -p "Subtle geometric pattern, pastel colors, website background" -o "./bg_pattern.png" -s 1440x720
undefinedz-ai image -p "柔和的几何图案,马卡龙色系,网站背景" -o "./bg_pattern.png" -s 1440x720
undefinedAdvanced Use Cases
高级使用场景
Batch Image Generation
批量图像生成
javascript
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
import path from 'path';
async function generateImageBatch(prompts, outputDir, size = '1024x1024') {
const zai = await ZAI.create();
// Ensure output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const results = [];
for (let i = 0; i < prompts.length; i++) {
try {
const prompt = prompts[i];
const filename = `image_${i + 1}.png`;
const outputPath = path.join(outputDir, filename);
const response = await zai.images.generations.create({
prompt: prompt,
size: size
});
const imageBase64 = response.data[0].base64;
const buffer = Buffer.from(imageBase64, 'base64');
fs.writeFileSync(outputPath, buffer);
results.push({
success: true,
prompt: prompt,
path: outputPath,
size: buffer.length
});
console.log(`✓ Generated: ${filename}`);
} catch (error) {
results.push({
success: false,
prompt: prompts[i],
error: error.message
});
console.error(`✗ Failed: ${prompts[i]} - ${error.message}`);
}
}
return results;
}
// Usage
const prompts = [
'A serene mountain landscape at sunset',
'A futuristic city with flying cars',
'An underwater coral reef teeming with life'
];
const results = await generateImageBatch(prompts, './generated-images');
console.log(`Generated ${results.filter(r => r.success).length} images`);javascript
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
import path from 'path';
async function generateImageBatch(prompts, outputDir, size = '1024x1024') {
const zai = await ZAI.create();
// 确保输出目录存在
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const results = [];
for (let i = 0; i < prompts.length; i++) {
try {
const prompt = prompts[i];
const filename = `image_${i + 1}.png`;
const outputPath = path.join(outputDir, filename);
const response = await zai.images.generations.create({
prompt: prompt,
size: size
});
const imageBase64 = response.data[0].base64;
const buffer = Buffer.from(imageBase64, 'base64');
fs.writeFileSync(outputPath, buffer);
results.push({
success: true,
prompt: prompt,
path: outputPath,
size: buffer.length
});
console.log(`✓ 已生成:${filename}`);
} catch (error) {
results.push({
success: false,
prompt: prompts[i],
error: error.message
});
console.error(`✗ 生成失败:${prompts[i]} - ${error.message}`);
}
}
return results;
}
// 使用示例
const prompts = [
"日落时分宁静的山景",
"拥有飞行汽车的未来城市",
"充满生机的水下珊瑚礁"
];
const results = await generateImageBatch(prompts, './generated-images');
console.log(`成功生成${results.filter(r => r.success).length}张图像`);Image Generation Service
图像生成服务类
javascript
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
class ImageGenerationService {
constructor(outputDir = './generated-images') {
this.outputDir = outputDir;
this.zai = null;
this.cache = new Map();
}
async initialize() {
this.zai = await ZAI.create();
if (!fs.existsSync(this.outputDir)) {
fs.mkdirSync(this.outputDir, { recursive: true });
}
}
generateCacheKey(prompt, size) {
return crypto
.createHash('md5')
.update(`${prompt}-${size}`)
.digest('hex');
}
async generate(prompt, options = {}) {
const {
size = '1024x1024',
useCache = true,
filename = null
} = options;
// Check cache
const cacheKey = this.generateCacheKey(prompt, size);
if (useCache && this.cache.has(cacheKey)) {
const cachedPath = this.cache.get(cacheKey);
if (fs.existsSync(cachedPath)) {
return {
path: cachedPath,
cached: true,
prompt: prompt,
size: size
};
}
}
// Generate new image
const response = await this.zai.images.generations.create({
prompt: prompt,
size: size
});
const imageBase64 = response.data[0].base64;
const buffer = Buffer.from(imageBase64, 'base64');
// Determine output path
const outputFilename = filename || `${cacheKey}.png`;
const outputPath = path.join(this.outputDir, outputFilename);
fs.writeFileSync(outputPath, buffer);
// Cache result
if (useCache) {
this.cache.set(cacheKey, outputPath);
}
return {
path: outputPath,
cached: false,
prompt: prompt,
size: size,
fileSize: buffer.length
};
}
clearCache() {
this.cache.clear();
}
getCacheSize() {
return this.cache.size;
}
}
// Usage
const service = new ImageGenerationService();
await service.initialize();
const result = await service.generate(
'A modern office space',
{ size: '1440x720' }
);
console.log('Generated:', result.path);javascript
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
class ImageGenerationService {
constructor(outputDir = './generated-images') {
this.outputDir = outputDir;
this.zai = null;
this.cache = new Map();
}
async initialize() {
this.zai = await ZAI.create();
if (!fs.existsSync(this.outputDir)) {
fs.mkdirSync(this.outputDir, { recursive: true });
}
}
generateCacheKey(prompt, size) {
return crypto
.createHash('md5')
.update(`${prompt}-${size}`)
.digest('hex');
}
async generate(prompt, options = {}) {
const {
size = '1024x1024',
useCache = true,
filename = null
} = options;
// 检查缓存
const cacheKey = this.generateCacheKey(prompt, size);
if (useCache && this.cache.has(cacheKey)) {
const cachedPath = this.cache.get(cacheKey);
if (fs.existsSync(cachedPath)) {
return {
path: cachedPath,
cached: true,
prompt: prompt,
size: size
};
}
}
// 生成新图像
const response = await this.zai.images.generations.create({
prompt: prompt,
size: size
});
const imageBase64 = response.data[0].base64;
const buffer = Buffer.from(imageBase64, 'base64');
// 确定输出路径
const outputFilename = filename || `${cacheKey}.png`;
const outputPath = path.join(this.outputDir, outputFilename);
fs.writeFileSync(outputPath, buffer);
// 缓存结果
if (useCache) {
this.cache.set(cacheKey, outputPath);
}
return {
path: outputPath,
cached: false,
prompt: prompt,
size: size,
fileSize: buffer.length
};
}
clearCache() {
this.cache.clear();
}
getCacheSize() {
return this.cache.size;
}
}
// 使用示例
const service = new ImageGenerationService();
await service.initialize();
const result = await service.generate(
"现代办公空间",
{ size: '1440x720' }
);
console.log('生成完成:', result.path);Website Asset Generator
网站资产生成
bash
undefinedbash
undefinedUsing CLI for quick website asset generation
使用CLI快速生成网站资产
z-ai image -p "Modern tech hero banner, blue gradient" -o "./assets/hero.png" -s 1440x720
z-ai image -p "Team collaboration illustration" -o "./assets/team.png" -s 1344x768
z-ai image -p "Simple geometric logo" -o "./assets/logo.png" -s 1024x1024
undefinedz-ai image -p "现代科技风格首屏横幅,蓝色渐变" -o "./assets/hero.png" -s 1440x720
z-ai image -p "团队协作插画" -o "./assets/team.png" -s 1344x768
z-ai image -p "简约几何Logo" -o "./assets/logo.png" -s 1024x1024
undefinedBest Practices
最佳实践
1. Effective Prompt Engineering
1. 高效提示词构建
javascript
function buildEffectivePrompt(subject, style, details = []) {
const components = [
subject,
style,
...details,
'high quality',
'detailed'
];
return components.filter(Boolean).join(', ');
}
// Usage
const prompt = buildEffectivePrompt(
'mountain landscape',
'oil painting style',
['sunset lighting', 'dramatic clouds', 'reflection in lake']
);
// Result: "mountain landscape, oil painting style, sunset lighting, dramatic clouds, reflection in lake, high quality, detailed"javascript
function buildEffectivePrompt(subject, style, details = []) {
const components = [
subject,
style,
...details,
'high quality',
'detailed'
];
return components.filter(Boolean).join(', ');
}
// 使用示例
const prompt = buildEffectivePrompt(
'山景',
'油画风格',
['日落光线', '戏剧性云层', '湖面倒影']
);
// 结果:"山景, 油画风格, 日落光线, 戏剧性云层, 湖面倒影, high quality, detailed"2. Size Selection Helper
2. 尺寸选择工具
javascript
function selectOptimalSize(purpose) {
const sizeMap = {
'hero-banner': '1440x720',
'blog-header': '1344x768',
'social-square': '1024x1024',
'portrait': '768x1344',
'product': '1024x1024',
'landscape': '1344x768',
'mobile-banner': '720x1440',
'thumbnail': '1024x1024'
};
return sizeMap[purpose] || '1024x1024';
}
// Usage
const size = selectOptimalSize('hero-banner');
await generateImage('website hero image', size, './hero.png');javascript
function selectOptimalSize(purpose) {
const sizeMap = {
'hero-banner': '1440x720',
'blog-header': '1344x768',
'social-square': '1024x1024',
'portrait': '768x1344',
'product': '1024x1024',
'landscape': '1344x768',
'mobile-banner': '720x1440',
'thumbnail': '1024x1024'
};
return sizeMap[purpose] || '1024x1024';
}
// 使用示例
const size = selectOptimalSize('hero-banner');
await generateImage('网站首屏图像', size, './hero.png');3. Error Handling
3. 错误处理
javascript
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
async function safeGenerateImage(prompt, size, outputPath, retries = 3) {
let lastError;
for (let attempt = 1; attempt <= retries; attempt++) {
try {
const zai = await ZAI.create();
const response = await zai.images.generations.create({
prompt: prompt,
size: size
});
if (!response.data || !response.data[0] || !response.data[0].base64) {
throw new Error('Invalid response from image generation API');
}
const imageBase64 = response.data[0].base64;
const buffer = Buffer.from(imageBase64, 'base64');
fs.writeFileSync(outputPath, buffer);
return {
success: true,
path: outputPath,
attempts: attempt
};
} catch (error) {
lastError = error;
console.error(`Attempt ${attempt} failed:`, error.message);
if (attempt < retries) {
// Wait before retry (exponential backoff)
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
}
}
}
return {
success: false,
error: lastError.message,
attempts: retries
};
}javascript
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
async function safeGenerateImage(prompt, size, outputPath, retries = 3) {
let lastError;
for (let attempt = 1; attempt <= retries; attempt++) {
try {
const zai = await ZAI.create();
const response = await zai.images.generations.create({
prompt: prompt,
size: size
});
if (!response.data || !response.data[0] || !response.data[0].base64) {
throw new Error('图像生成API返回无效响应');
}
const imageBase64 = response.data[0].base64;
const buffer = Buffer.from(imageBase64, 'base64');
fs.writeFileSync(outputPath, buffer);
return {
success: true,
path: outputPath,
attempts: attempt
};
} catch (error) {
lastError = error;
console.error(`第${attempt}次尝试失败:`, error.message);
if (attempt < retries) {
// 重试前等待(指数退避)
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
}
}
}
return {
success: false,
error: lastError.message,
attempts: retries
};
}Common Use Cases
常见使用场景
- Website Design: Generate hero images, backgrounds, and visual assets
- Marketing Materials: Create social media graphics and promotional images
- Product Visualization: Generate product mockups and variations
- Content Creation: Produce blog post illustrations and thumbnails
- Brand Assets: Create logos, icons, and brand imagery
- UI/UX Design: Generate interface elements and illustrations
- Game Development: Create concept art and game assets
- E-commerce: Generate product images and lifestyle shots
- 网站设计:生成首屏图像、背景和视觉资产
- 营销物料:创建社交媒体图形和推广图像
- 产品可视化:生成产品模型和变体
- 内容创作:制作博客文章插图和缩略图
- 品牌资产:创建Logo、图标和品牌视觉
- UI/UX设计:生成界面元素和插画
- 游戏开发:创建概念艺术和游戏资产
- 电子商务:生成产品图像和生活场景图
Integration Examples
集成示例
Express.js API Endpoint
Express.js API接口
javascript
import express from 'express';
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
import path from 'path';
const app = express();
app.use(express.json());
app.use('/images', express.static('generated-images'));
let zaiInstance;
const outputDir = './generated-images';
async function initZAI() {
zaiInstance = await ZAI.create();
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
}
app.post('/api/generate-image', async (req, res) => {
try {
const { prompt, size = '1024x1024' } = req.body;
if (!prompt) {
return res.status(400).json({ error: 'Prompt is required' });
}
const response = await zaiInstance.images.generations.create({
prompt: prompt,
size: size
});
const imageBase64 = response.data[0].base64;
const buffer = Buffer.from(imageBase64, 'base64');
const filename = `img_${Date.now()}.png`;
const filepath = path.join(outputDir, filename);
fs.writeFileSync(filepath, buffer);
res.json({
success: true,
imageUrl: `/images/${filename}`,
prompt: prompt,
size: size
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
});
initZAI().then(() => {
app.listen(3000, () => {
console.log('Image generation API running on port 3000');
});
});javascript
import express from 'express';
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
import path from 'path';
const app = express();
app.use(express.json());
app.use('/images', express.static('generated-images'));
let zaiInstance;
const outputDir = './generated-images';
async function initZAI() {
zaiInstance = await ZAI.create();
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
}
app.post('/api/generate-image', async (req, res) => {
try {
const { prompt, size = '1024x1024' } = req.body;
if (!prompt) {
return res.status(400).json({ error: '提示词为必填项' });
}
const response = await zaiInstance.images.generations.create({
prompt: prompt,
size: size
});
const imageBase64 = response.data[0].base64;
const buffer = Buffer.from(imageBase64, 'base64');
const filename = `img_${Date.now()}.png`;
const filepath = path.join(outputDir, filename);
fs.writeFileSync(filepath, buffer);
res.json({
success: true,
imageUrl: `/images/${filename}`,
prompt: prompt,
size: size
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
});
initZAI().then(() => {
app.listen(3000, () => {
console.log('图像生成API运行在3000端口');
});
});CLI Integration in Scripts
CLI在脚本中的集成
Shell Script Example
Shell脚本示例
bash
#!/bin/bashbash
#!/bin/bashGenerate website assets using CLI
使用CLI生成网站资产
echo "Generating website assets..."
z-ai image -p "Modern tech hero banner, blue gradient" -o "./assets/hero.png" -s 1440x720
z-ai image -p "Team collaboration illustration" -o "./assets/team.png" -s 1344x768
z-ai image -p "Simple geometric logo" -o "./assets/logo.png" -s 1024x1024
echo "Assets generated successfully!"
undefinedecho "正在生成网站资产..."
z-ai image -p "现代科技风格首屏横幅,蓝色渐变" -o "./assets/hero.png" -s 1440x720
z-ai image -p "团队协作插画" -o "./assets/team.png" -s 1344x768
z-ai image -p "简约几何Logo" -o "./assets/logo.png" -s 1024x1024
echo "资产生成完成!"
undefinedTroubleshooting
故障排除
Issue: "SDK must be used in backend"
- Solution: Ensure z-ai-web-dev-sdk is only used in server-side code
Issue: Invalid size parameter
- Solution: Use only supported sizes: 1024x1024, 768x1344, 864x1152, 1344x768, 1152x864, 1440x720, 720x1440
Issue: Generated image doesn't match prompt
- Solution: Make prompts more specific and descriptive. Include style, details, and quality terms
Issue: CLI command not found
- Solution: Ensure z-ai CLI is properly installed and in PATH
Issue: Image file is corrupted
- Solution: Verify base64 decoding and file writing are correct
问题:"SDK必须在后端使用"
- 解决方案:确保z-ai-web-dev-sdk仅用于服务器端代码
问题:无效的尺寸参数
- 解决方案:仅使用支持的尺寸:1024x1024、768x1344、864x1152、1344x768、1152x864、1440x720、720x1440
问题:生成的图像与提示词不符
- 解决方案:使用更具体、详细的提示词,包含风格、细节和质量描述
问题:CLI命令未找到
- 解决方案:确保z-ai CLI已正确安装并添加到系统PATH中
问题:图像文件损坏
- 解决方案:验证Base64解码和文件写入逻辑是否正确
Prompt Engineering Tips
提示词工程技巧
Good Prompts
优秀提示词示例
- ✓ "Professional product photography of wireless headphones, white background, studio lighting, high quality"
- ✓ "Mountain landscape at golden hour, oil painting style, dramatic clouds, detailed"
- ✓ "Modern minimalist logo for tech company, blue and white, geometric shapes"
- ✓ "无线耳机的专业产品摄影,白色背景,影棚灯光,高质量"
- ✓ "黄金时段的山景,油画风格,戏剧性云层,细节丰富"
- ✓ "科技公司的现代极简Logo,蓝白色调,几何形状"
Poor Prompts
糟糕提示词示例
- ✗ "headphones"
- ✗ "picture of mountains"
- ✗ "logo"
- ✗ "耳机"
- ✗ "山的图片"
- ✗ "Logo"
Prompt Components
提示词组成部分
- Subject: What you want to see
- Style: Art style, photography style, etc.
- Details: Specific elements, colors, mood
- Quality: "high quality", "detailed", "professional"
- 主体:你想要呈现的内容
- 风格:艺术风格、摄影风格等
- 细节:特定元素、颜色、氛围
- 质量:"high quality"、"detailed"、"professional"
Supported Image Sizes
支持的图像尺寸
- - Square
1024x1024 - - Portrait
768x1344 - - Portrait
864x1152 - - Landscape
1344x768 - - Landscape
1152x864 - - Wide landscape
1440x720 - - Tall portrait
720x1440
- - 正方形
1024x1024 - - 竖版
768x1344 - - 竖版
864x1152 - - 横版
1344x768 - - 横版
1152x864 - - 宽幅横版
1440x720 - - 长竖版
720x1440
Remember
注意事项
- Always use z-ai-web-dev-sdk in backend code only
- The SDK is already installed - import as shown
- CLI tool is available for quick image generation
- Supported sizes are specific - use the provided list
- Base64 images need to be decoded before saving
- Consider caching for repeated prompts
- Implement retry logic for production applications
- Use descriptive prompts for better results
- 始终仅在后端代码中使用z-ai-web-dev-sdk
- SDK已预先安装,可按照示例导入
- CLI工具可用于快速生成图像
- 仅使用支持的特定尺寸
- Base64图像需要解码后才能保存
- 对于重复的提示词可考虑使用缓存
- 生产环境应用需实现重试逻辑
- 使用详细的提示词以获得更好的结果