[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75DJS32DRT5PBK6140DZRDZ":3,"skill-same:01M75DJS32DRT5PBK6140DZRDZ":56},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":15,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":13,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":29,"updatedAt":30,"install":31,"resources":44},"01M75DJS32DRT5PBK6140DZRDZ","image-generation",null,"Implement AI image generation capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to create images from text descriptions, generate visual content, create artwork, design assets, or build applications with AI-powered image creation. Supports multiple image sizes and returns base64 encoded images. Also includes CLI tool for quick image generation.","nordeim\u002Fonestopnews","nordeim","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F194583642?v=4","01M75CZEV8C3V4DDQNPQ1EA7QJ","01M75CZEWBH4NQBG9THF3SKTRE",0,"MIT","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fimage-generation\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fimage-generation\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: image-generation\ndescription: Implement AI image generation capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to create images from text descriptions, generate visual content, create artwork, design assets, or build applications with AI-powered image creation. Supports multiple image sizes and returns base64 encoded images. Also includes CLI tool for quick image generation.\nlicense: MIT\n---\n\n# Image Generation Skill\n\nThis 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.\n\n## Skills Path\n\n**Skill Location**: `{project_path}\u002Fskills\u002Fimage-generation`\n\nthis skill is located at above path in your project.\n\n**Reference Scripts**: Example test scripts are available in the `{Skill Location}\u002Fscripts\u002F` directory for quick testing and reference. See `{Skill Location}\u002Fscripts\u002Fimage-generation.ts` for a working example.\n\n## Overview\n\nImage 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.\n\n**IMPORTANT**: z-ai-web-dev-sdk MUST be used in backend code only. Never use it in client-side code.\n\n## Prerequisites\n\nThe z-ai-web-dev-sdk package is already installed. Import it as shown in the examples below.\n\n## Basic Image Generation\n\n### Simple Image Creation\n\n```javascript\nimport ZAI from 'z-ai-web-dev-sdk';\nimport fs from 'fs';\n\nasync function generateImage(prompt, outputPath) {\n  const zai = await ZAI.create();\n\n  const response = await zai.images.generations.create({\n    prompt: prompt,\n    size: '1024x1024'\n  });\n\n  const imageBase64 = response.data[0].base64;\n  \n  \u002F\u002F Save image\n  const buffer = Buffer.from(imageBase64, 'base64');\n  fs.writeFileSync(outputPath, buffer);\n  \n  console.log(`Image saved to ${outputPath}`);\n  return outputPath;\n}\n\n\u002F\u002F Usage\nawait generateImage(\n  'A cute cat playing in the garden',\n  '.\u002Fcat_image.png'\n);\n```\n\n### Multiple Image Sizes\n\n```javascript\nimport ZAI from 'z-ai-web-dev-sdk';\nimport fs from 'fs';\n\n\u002F\u002F Supported sizes\nconst SUPPORTED_SIZES = [\n  '1024x1024',  \u002F\u002F Square\n  '768x1344',   \u002F\u002F Portrait\n  '864x1152',   \u002F\u002F Portrait\n  '1344x768',   \u002F\u002F Landscape\n  '1152x864',   \u002F\u002F Landscape\n  '1440x720',   \u002F\u002F Wide landscape\n  '720x1440'    \u002F\u002F Tall portrait\n];\n\nasync function generateImageWithSize(prompt, size, outputPath) {\n  if (!SUPPORTED_SIZES.includes(size)) {\n    throw new Error(`Unsupported size: ${size}. Use one of: ${SUPPORTED_SIZES.join(', ')}`);\n  }\n\n  const zai = await ZAI.create();\n\n  const response = await zai.images.generations.create({\n    prompt: prompt,\n    size: size\n  });\n\n  const imageBase64 = response.data[0].base64;\n  const buffer = Buffer.from(imageBase64, 'base64');\n  fs.writeFileSync(outputPath, buffer);\n\n  return {\n    path: outputPath,\n    size: size,\n    fileSize: buffer.length\n  };\n}\n\n\u002F\u002F Usage - Different sizes\nawait generateImageWithSize(\n  'A beautiful landscape',\n  '1344x768',\n  '.\u002Flandscape.png'\n);\n\nawait generateImageWithSize(\n  'A portrait of a person',\n  '768x1344',\n  '.\u002Fportrait.png'\n);\n```\n\n## CLI Tool Usage\n\nThe z-ai CLI tool provides a convenient way to generate images directly from the command line.\n\n### Basic CLI Usage\n\n```bash\n# Generate image with full options\nz-ai image --prompt \"A beautiful landscape\" --output \".\u002Fimage.png\"\n\n# Short form\nz-ai image -p \"A cute cat\" -o \".\u002Fcat.png\"\n\n# Specify size\nz-ai image -p \"A sunset\" -o \".\u002Fsunset.png\" -s 1344x768\n\n# Portrait orientation\nz-ai image -p \"A portrait\" -o \".\u002Fportrait.png\" -s 768x1344\n```\n\n### CLI Use Cases\n\n```bash\n# Website hero image\nz-ai image -p \"Modern tech office with diverse team collaborating\" -o \".\u002Fhero.png\" -s 1440x720\n\n# Product image\nz-ai image -p \"Sleek smartphone on minimalist desk, professional product photography\" -o \".\u002Fproduct.png\" -s 1024x1024\n\n# Blog post illustration\nz-ai image -p \"Abstract visualization of data flowing through networks\" -o \".\u002Fblog_header.png\" -s 1344x768\n\n# Social media content\nz-ai image -p \"Vibrant illustration of community connection\" -o \".\u002Fsocial.png\" -s 1024x1024\n\n# Website favicon\u002Flogo\nz-ai image -p \"Simple geometric logo with blue gradient, minimal design\" -o \".\u002Flogo.png\" -s 1024x1024\n\n# Background pattern\nz-ai image -p \"Subtle geometric pattern, pastel colors, website background\" -o \".\u002Fbg_pattern.png\" -s 1440x720\n```\n\n## Advanced Use Cases\n\n### Batch Image Generation\n\n```javascript\nimport ZAI from 'z-ai-web-dev-sdk';\nimport fs from 'fs';\nimport path from 'path';\n\nasync function generateImageBatch(prompts, outputDir, size = '1024x1024') {\n  const zai = await ZAI.create();\n\n  \u002F\u002F Ensure output directory exists\n  if (!fs.existsSync(outputDir)) {\n    fs.mkdirSync(outputDir, { recursive: true });\n  }\n\n  const results = [];\n\n  for (let i = 0; i \u003C prompts.length; i++) {\n    try {\n      const prompt = prompts[i];\n      const filename = `image_${i + 1}.png`;\n      const outputPath = path.join(outputDir, filename);\n\n      const response = await zai.images.generations.create({\n        prompt: prompt,\n        size: size\n      });\n\n      const imageBase64 = response.data[0].base64;\n      const buffer = Buffer.from(imageBase64, 'base64');\n      fs.writeFileSync(outputPath, buffer);\n\n      results.push({\n        success: true,\n        prompt: prompt,\n        path: outputPath,\n        size: buffer.length\n      });\n\n      console.log(`✓ Generated: ${filename}`);\n    } catch (error) {\n      results.push({\n        success: false,\n        prompt: prompts[i],\n        error: error.message\n      });\n\n      console.error(`✗ Failed: ${prompts[i]} - ${error.message}`);\n    }\n  }\n\n  return results;\n}\n\n\u002F\u002F Usage\nconst prompts = [\n  'A serene mountain landscape at sunset',\n  'A futuristic city with flying cars',\n  'An underwater coral reef teeming with life'\n];\n\nconst results = await generateImageBatch(prompts, '.\u002Fgenerated-images');\nconsole.log(`Generated ${results.filter(r => r.success).length} images`);\n```\n\n### Image Generation Service\n\n```javascript\nimport ZAI from 'z-ai-web-dev-sdk';\nimport fs from 'fs';\nimport path from 'path';\nimport crypto from 'crypto';\n\nclass ImageGenerationService {\n  constructor(outputDir = '.\u002Fgenerated-images') {\n    this.outputDir = outputDir;\n    this.zai = null;\n    this.cache = new Map();\n  }\n\n  async initialize() {\n    this.zai = await ZAI.create();\n    \n    if (!fs.existsSync(this.outputDir)) {\n      fs.mkdirSync(this.outputDir, { recursive: true });\n    }\n  }\n\n  generateCacheKey(prompt, size) {\n    return crypto\n      .createHash('md5')\n      .update(`${prompt}-${size}`)\n      .digest('hex');\n  }\n\n  async generate(prompt, options = {}) {\n    const {\n      size = '1024x1024',\n      useCache = true,\n      filename = null\n    } = options;\n\n    \u002F\u002F Check cache\n    const cacheKey = this.generateCacheKey(prompt, size);\n    \n    if (useCache && this.cache.has(cacheKey)) {\n      const cachedPath = this.cache.get(cacheKey);\n      if (fs.existsSync(cachedPath)) {\n        return {\n          path: cachedPath,\n          cached: true,\n          prompt: prompt,\n          size: size\n        };\n      }\n    }\n\n    \u002F\u002F Generate new image\n    const response = await this.zai.images.generations.create({\n      prompt: prompt,\n      size: size\n    });\n\n    const imageBase64 = response.data[0].base64;\n    const buffer = Buffer.from(imageBase64, 'base64');\n\n    \u002F\u002F Determine output path\n    const outputFilename = filename || `${cacheKey}.png`;\n    const outputPath = path.join(this.outputDir, outputFilename);\n\n    fs.writeFileSync(outputPath, buffer);\n\n    \u002F\u002F Cache result\n    if (useCache) {\n      this.cache.set(cacheKey, outputPath);\n    }\n\n    return {\n      path: outputPath,\n      cached: false,\n      prompt: prompt,\n      size: size,\n      fileSize: buffer.length\n    };\n  }\n\n  clearCache() {\n    this.cache.clear();\n  }\n\n  getCacheSize() {\n    return this.cache.size;\n  }\n}\n\n\u002F\u002F Usage\nconst service = new ImageGenerationService();\nawait service.initialize();\n\nconst result = await service.generate(\n  'A modern office space',\n  { size: '1440x720' }\n);\n\nconsole.log('Generated:', result.path);\n```\n\n### Website Asset Generator\n\n```bash\n# Using CLI for quick website asset generation\nz-ai image -p \"Modern tech hero banner, blue gradient\" -o \".\u002Fassets\u002Fhero.png\" -s 1440x720\nz-ai image -p \"Team collaboration illustration\" -o \".\u002Fassets\u002Fteam.png\" -s 1344x768\nz-ai image -p \"Simple geometric logo\" -o \".\u002Fassets\u002Flogo.png\" -s 1024x1024\n```\n\n## Best Practices\n\n### 1. Effective Prompt Engineering\n\n```javascript\nfunction buildEffectivePrompt(subject, style, details = []) {\n  const components = [\n    subject,\n    style,\n    ...details,\n    'high quality',\n    'detailed'\n  ];\n\n  return components.filter(Boolean).join(', ');\n}\n\n\u002F\u002F Usage\nconst prompt = buildEffectivePrompt(\n  'mountain landscape',\n  'oil painting style',\n  ['sunset lighting', 'dramatic clouds', 'reflection in lake']\n);\n\n\u002F\u002F Result: \"mountain landscape, oil painting style, sunset lighting, dramatic clouds, reflection in lake, high quality, detailed\"\n```\n\n### 2. Size Selection Helper\n\n```javascript\nfunction selectOptimalSize(purpose) {\n  const sizeMap = {\n    'hero-banner': '1440x720',\n    'blog-header': '1344x768',\n    'social-square': '1024x1024',\n    'portrait': '768x1344',\n    'product': '1024x1024',\n    'landscape': '1344x768',\n    'mobile-banner': '720x1440',\n    'thumbnail': '1024x1024'\n  };\n\n  return sizeMap[purpose] || '1024x1024';\n}\n\n\u002F\u002F Usage\nconst size = selectOptimalSize('hero-banner');\nawait generateImage('website hero image', size, '.\u002Fhero.png');\n```\n\n### 3. Error Handling\n\n```javascript\nimport ZAI from 'z-ai-web-dev-sdk';\nimport fs from 'fs';\n\nasync function safeGenerateImage(prompt, size, outputPath, retries = 3) {\n  let lastError;\n\n  for (let attempt = 1; attempt \u003C= retries; attempt++) {\n    try {\n      const zai = await ZAI.create();\n\n      const response = await zai.images.generations.create({\n        prompt: prompt,\n        size: size\n      });\n\n      if (!response.data || !response.data[0] || !response.data[0].base64) {\n        throw new Error('Invalid response from image generation API');\n      }\n\n      const imageBase64 = response.data[0].base64;\n      const buffer = Buffer.from(imageBase64, 'base64');\n      fs.writeFileSync(outputPath, buffer);\n\n      return {\n        success: true,\n        path: outputPath,\n        attempts: attempt\n      };\n    } catch (error) {\n      lastError = error;\n      console.error(`Attempt ${attempt} failed:`, error.message);\n\n      if (attempt \u003C retries) {\n        \u002F\u002F Wait before retry (exponential backoff)\n        await new Promise(resolve => setTimeout(resolve, 1000 * attempt));\n      }\n    }\n  }\n\n  return {\n    success: false,\n    error: lastError.message,\n    attempts: retries\n  };\n}\n```\n\n## Common Use Cases\n\n1. **Website Design**: Generate hero images, backgrounds, and visual assets\n2. **Marketing Materials**: Create social media graphics and promotional images\n3. **Product Visualization**: Generate product mockups and variations\n4. **Content Creation**: Produce blog post illustrations and thumbnails\n5. **Brand Assets**: Create logos, icons, and brand imagery\n6. **UI\u002FUX Design**: Generate interface elements and illustrations\n7. **Game Development**: Create concept art and game assets\n8. **E-commerce**: Generate product images and lifestyle shots\n\n## Integration Examples\n\n### Express.js API Endpoint\n\n```javascript\nimport express from 'express';\nimport ZAI from 'z-ai-web-dev-sdk';\nimport fs from 'fs';\nimport path from 'path';\n\nconst app = express();\napp.use(express.json());\napp.use('\u002Fimages', express.static('generated-images'));\n\nlet zaiInstance;\nconst outputDir = '.\u002Fgenerated-images';\n\nasync function initZAI() {\n  zaiInstance = await ZAI.create();\n  if (!fs.existsSync(outputDir)) {\n    fs.mkdirSync(outputDir, { recursive: true });\n  }\n}\n\napp.post('\u002Fapi\u002Fgenerate-image', async (req, res) => {\n  try {\n    const { prompt, size = '1024x1024' } = req.body;\n\n    if (!prompt) {\n      return res.status(400).json({ error: 'Prompt is required' });\n    }\n\n    const response = await zaiInstance.images.generations.create({\n      prompt: prompt,\n      size: size\n    });\n\n    const imageBase64 = response.data[0].base64;\n    const buffer = Buffer.from(imageBase64, 'base64');\n    \n    const filename = `img_${Date.now()}.png`;\n    const filepath = path.join(outputDir, filename);\n    fs.writeFileSync(filepath, buffer);\n\n    res.json({\n      success: true,\n      imageUrl: `\u002Fimages\u002F${filename}`,\n      prompt: prompt,\n      size: size\n    });\n  } catch (error) {\n    res.status(500).json({\n      success: false,\n      error: error.message\n    });\n  }\n});\n\ninitZAI().then(() => {\n  app.listen(3000, () => {\n    console.log('Image generation API running on port 3000');\n  });\n});\n```\n\n## CLI Integration in Scripts\n\n### Shell Script Example\n\n```bash\n#!\u002Fbin\u002Fbash\n\n# Generate website assets using CLI\necho \"Generating website assets...\"\n\nz-ai image -p \"Modern tech hero banner, blue gradient\" -o \".\u002Fassets\u002Fhero.png\" -s 1440x720\nz-ai image -p \"Team collaboration illustration\" -o \".\u002Fassets\u002Fteam.png\" -s 1344x768\nz-ai image -p \"Simple geometric logo\" -o \".\u002Fassets\u002Flogo.png\" -s 1024x1024\n\necho \"Assets generated successfully!\"\n```\n\n## Troubleshooting\n\n**Issue**: \"SDK must be used in backend\"\n- **Solution**: Ensure z-ai-web-dev-sdk is only used in server-side code\n\n**Issue**: Invalid size parameter\n- **Solution**: Use only supported sizes: 1024x1024, 768x1344, 864x1152, 1344x768, 1152x864, 1440x720, 720x1440\n\n**Issue**: Generated image doesn't match prompt\n- **Solution**: Make prompts more specific and descriptive. Include style, details, and quality terms\n\n**Issue**: CLI command not found\n- **Solution**: Ensure z-ai CLI is properly installed and in PATH\n\n**Issue**: Image file is corrupted\n- **Solution**: Verify base64 decoding and file writing are correct\n\n## Prompt Engineering Tips\n\n### Good Prompts\n- ✓ \"Professional product photography of wireless headphones, white background, studio lighting, high quality\"\n- ✓ \"Mountain landscape at golden hour, oil painting style, dramatic clouds, detailed\"\n- ✓ \"Modern minimalist logo for tech company, blue and white, geometric shapes\"\n\n### Poor Prompts\n- ✗ \"headphones\"\n- ✗ \"picture of mountains\"\n- ✗ \"logo\"\n\n### Prompt Components\n1. **Subject**: What you want to see\n2. **Style**: Art style, photography style, etc.\n3. **Details**: Specific elements, colors, mood\n4. **Quality**: \"high quality\", \"detailed\", \"professional\"\n\n## Supported Image Sizes\n\n- `1024x1024` - Square\n- `768x1344` - Portrait\n- `864x1152` - Portrait\n- `1344x768` - Landscape\n- `1152x864` - Landscape\n- `1440x720` - Wide landscape\n- `720x1440` - Tall portrait\n\n## Remember\n\n- Always use z-ai-web-dev-sdk in backend code only\n- The SDK is already installed - import as shown\n- CLI tool is available for quick image generation\n- Supported sizes are specific - use the provided list\n- Base64 images need to be decoded before saving\n- Consider caching for repeated prompts\n- Implement retry logic for production applications\n- Use descriptive prompts for better results\n","# Image Generation Skill\n\nThis 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.\n\n## Skills Path\n\n**Skill Location**: `{project_path}\u002Fskills\u002Fimage-generation`\n\nthis skill is located at above path in your project.\n\n**Reference Scripts**: Example test scripts are available in the `{Skill Location}\u002Fscripts\u002F` directory for quick testing and reference. See `{Skill Location}\u002Fscripts\u002Fimage-generation.ts` for a working example.\n\n## Overview\n\nImage 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.\n\n**IMPORTANT**: z-ai-web-dev-sdk MUST be used in backend code only. Never use it in client-side code.\n\n## Prerequisites\n\nThe z-ai-web-dev-sdk package is already installed. Import it as shown in the examples below.\n\n## Basic Image Generation\n\n### Simple Image Creation\n\n```javascript\nimport ZAI from 'z-ai-web-dev-sdk';\nimport fs from 'fs';\n\nasync function generateImage(prompt, outputPath) {\n  const zai = await ZAI.create();\n\n  const response = await zai.images.generations.create({\n    prompt: prompt,\n    size: '1024x1024'\n  });\n\n  const imageBase64 = response.data[0].base64;\n  \n  \u002F\u002F Save image\n  const buffer = Buffer.from(imageBase64, 'base64');\n  fs.writeFileSync(outputPath, buffer);\n  \n  console.log(`Image saved to ${outputPath}`);\n  return outputPath;\n}\n\n\u002F\u002F Usage\nawait generateImage(\n  'A cute cat playing in the garden',\n  '.\u002Fcat_image.png'\n);\n```\n\n### Multiple Image Sizes\n\n```javascript\nimport ZAI from 'z-ai-web-dev-sdk';\nimport fs from 'fs';\n\n\u002F\u002F Supported sizes\nconst SUPPORTED_SIZES = [\n  '1024x1024',  \u002F\u002F Square\n  '768x1344',   \u002F\u002F Portrait\n  '864x1152',   \u002F\u002F Portrait\n  '1344x768',   \u002F\u002F Landscape\n  '1152x864',   \u002F\u002F Landscape\n  '1440x720',   \u002F\u002F Wide landscape\n  '720x1440'    \u002F\u002F Tall portrait\n];\n\nasync function generateImageWithSize(prompt, size, outputPath) {\n  if (!SUPPORTED_SIZES.includes(size)) {\n    throw new Error(`Unsupported size: ${size}. Use one of: ${SUPPORTED_SIZES.join(', ')}`);\n  }\n\n  const zai = await ZAI.create();\n\n  const response = await zai.images.generations.create({\n    prompt: prompt,\n    size: size\n  });\n\n  const imageBase64 = response.data[0].base64;\n  const buffer = Buffer.from(imageBase64, 'base64');\n  fs.writeFileSync(outputPath, buffer);\n\n  return {\n    path: outputPath,\n    size: size,\n    fileSize: buffer.length\n  };\n}\n\n\u002F\u002F Usage - Different sizes\nawait generateImageWithSize(\n  'A beautiful landscape',\n  '1344x768',\n  '.\u002Flandscape.png'\n);\n\nawait generateImageWithSize(\n  'A portrait of a person',\n  '768x1344',\n  '.\u002Fportrait.png'\n);\n```\n\n## CLI Tool Usage\n\nThe z-ai CLI tool provides a convenient way to generate images directly from the command line.\n\n### Basic CLI Usage\n\n```bash\n# Generate image with full options\nz-ai image --prompt \"A beautiful landscape\" --output \".\u002Fimage.png\"\n\n# Short form\nz-ai image -p \"A cute cat\" -o \".\u002Fcat.png\"\n\n# Specify size\nz-ai image -p \"A sunset\" -o \".\u002Fsunset.png\" -s 1344x768\n\n# Portrait orientation\nz-ai image -p \"A portrait\" -o \".\u002Fportrait.png\" -s 768x1344\n```\n\n### CLI Use Cases\n\n```bash\n# Website hero image\nz-ai image -p \"Modern tech office with diverse team collaborating\" -o \".\u002Fhero.png\" -s 1440x720\n\n# Product image\nz-ai image -p \"Sleek smartphone on minimalist desk, professional product photography\" -o \".\u002Fproduct.png\" -s 1024x1024\n\n# Blog post illustration\nz-ai image -p \"Abstract visualization of data flowing through networks\" -o \".\u002Fblog_header.png\" -s 1344x768\n\n# Social media content\nz-ai image -p \"Vibrant illustration of community connection\" -o \".\u002Fsocial.png\" -s 1024x1024\n\n# Website favicon\u002Flogo\nz-ai image -p \"Simple geometric logo with blue gradient, minimal design\" -o \".\u002Flogo.png\" -s 1024x1024\n\n# Background pattern\nz-ai image -p \"Subtle geometric pattern, pastel colors, website background\" -o \".\u002Fbg_pattern.png\" -s 1440x720\n```\n\n## Advanced Use Cases\n\n### Batch Image Generation\n\n```javascript\nimport ZAI from 'z-ai-web-dev-sdk';\nimport fs from 'fs';\nimport path from 'path';\n\nasync function generateImageBatch(prompts, outputDir, size = '1024x1024') {\n  const zai = await ZAI.create();\n\n  \u002F\u002F Ensure output directory exists\n  if (!fs.existsSync(outputDir)) {\n    fs.mkdirSync(outputDir, { recursive: true });\n  }\n\n  const results = [];\n\n  for (let i = 0; i \u003C prompts.length; i++) {\n    try {\n      const prompt = prompts[i];\n      const filename = `image_${i + 1}.png`;\n      const outputPath = path.join(outputDir, filename);\n\n      const response = await zai.images.generations.create({\n        prompt: prompt,\n        size: size\n      });\n\n      const imageBase64 = response.data[0].base64;\n      const buffer = Buffer.from(imageBase64, 'base64');\n      fs.writeFileSync(outputPath, buffer);\n\n      results.push({\n        success: true,\n        prompt: prompt,\n        path: outputPath,\n        size: buffer.length\n      });\n\n      console.log(`✓ Generated: ${filename}`);\n    } catch (error) {\n      results.push({\n        success: false,\n        prompt: prompts[i],\n        error: error.message\n      });\n\n      console.error(`✗ Failed: ${prompts[i]} - ${error.message}`);\n    }\n  }\n\n  return results;\n}\n\n\u002F\u002F Usage\nconst prompts = [\n  'A serene mountain landscape at sunset',\n  'A futuristic city with flying cars',\n  'An underwater coral reef teeming with life'\n];\n\nconst results = await generateImageBatch(prompts, '.\u002Fgenerated-images');\nconsole.log(`Generated ${results.filter(r => r.success).length} images`);\n```\n\n### Image Generation Service\n\n```javascript\nimport ZAI from 'z-ai-web-dev-sdk';\nimport fs from 'fs';\nimport path from 'path';\nimport crypto from 'crypto';\n\nclass ImageGenerationService {\n  constructor(outputDir = '.\u002Fgenerated-images') {\n    this.outputDir = outputDir;\n    this.zai = null;\n    this.cache = new Map();\n  }\n\n  async initialize() {\n    this.zai = await ZAI.create();\n    \n    if (!fs.existsSync(this.outputDir)) {\n      fs.mkdirSync(this.outputDir, { recursive: true });\n    }\n  }\n\n  generateCacheKey(prompt, size) {\n    return crypto\n      .createHash('md5')\n      .update(`${prompt}-${size}`)\n      .digest('hex');\n  }\n\n  async generate(prompt, options = {}) {\n    const {\n      size = '1024x1024',\n      useCache = true,\n      filename = null\n    } = options;\n\n    \u002F\u002F Check cache\n    const cacheKey = this.generateCacheKey(prompt, size);\n    \n    if (useCache && this.cache.has(cacheKey)) {\n      const cachedPath = this.cache.get(cacheKey);\n      if (fs.existsSync(cachedPath)) {\n        return {\n          path: cachedPath,\n          cached: true,\n          prompt: prompt,\n          size: size\n        };\n      }\n    }\n\n    \u002F\u002F Generate new image\n    const response = await this.zai.images.generations.create({\n      prompt: prompt,\n      size: size\n    });\n\n    const imageBase64 = response.data[0].base64;\n    const buffer = Buffer.from(imageBase64, 'base64');\n\n    \u002F\u002F Determine output path\n    const outputFilename = filename || `${cacheKey}.png`;\n    const outputPath = path.join(this.outputDir, outputFilename);\n\n    fs.writeFileSync(outputPath, buffer);\n\n    \u002F\u002F Cache result\n    if (useCache) {\n      this.cache.set(cacheKey, outputPath);\n    }\n\n    return {\n      path: outputPath,\n      cached: false,\n      prompt: prompt,\n      size: size,\n      fileSize: buffer.length\n    };\n  }\n\n  clearCache() {\n    this.cache.clear();\n  }\n\n  getCacheSize() {\n    return this.cache.size;\n  }\n}\n\n\u002F\u002F Usage\nconst service = new ImageGenerationService();\nawait service.initialize();\n\nconst result = await service.generate(\n  'A modern office space',\n  { size: '1440x720' }\n);\n\nconsole.log('Generated:', result.path);\n```\n\n### Website Asset Generator\n\n```bash\n# Using CLI for quick website asset generation\nz-ai image -p \"Modern tech hero banner, blue gradient\" -o \".\u002Fassets\u002Fhero.png\" -s 1440x720\nz-ai image -p \"Team collaboration illustration\" -o \".\u002Fassets\u002Fteam.png\" -s 1344x768\nz-ai image -p \"Simple geometric logo\" -o \".\u002Fassets\u002Flogo.png\" -s 1024x1024\n```\n\n## Best Practices\n\n### 1. Effective Prompt Engineering\n\n```javascript\nfunction buildEffectivePrompt(subject, style, details = []) {\n  const components = [\n    subject,\n    style,\n    ...details,\n    'high quality',\n    'detailed'\n  ];\n\n  return components.filter(Boolean).join(', ');\n}\n\n\u002F\u002F Usage\nconst prompt = buildEffectivePrompt(\n  'mountain landscape',\n  'oil painting style',\n  ['sunset lighting', 'dramatic clouds', 'reflection in lake']\n);\n\n\u002F\u002F Result: \"mountain landscape, oil painting style, sunset lighting, dramatic clouds, reflection in lake, high quality, detailed\"\n```\n\n### 2. Size Selection Helper\n\n```javascript\nfunction selectOptimalSize(purpose) {\n  const sizeMap = {\n    'hero-banner': '1440x720',\n    'blog-header': '1344x768',\n    'social-square': '1024x1024',\n    'portrait': '768x1344',\n    'product': '1024x1024',\n    'landscape': '1344x768',\n    'mobile-banner': '720x1440',\n    'thumbnail': '1024x1024'\n  };\n\n  return sizeMap[purpose] || '1024x1024';\n}\n\n\u002F\u002F Usage\nconst size = selectOptimalSize('hero-banner');\nawait generateImage('website hero image', size, '.\u002Fhero.png');\n```\n\n### 3. Error Handling\n\n```javascript\nimport ZAI from 'z-ai-web-dev-sdk';\nimport fs from 'fs';\n\nasync function safeGenerateImage(prompt, size, outputPath, retries = 3) {\n  let lastError;\n\n  for (let attempt = 1; attempt \u003C= retries; attempt++) {\n    try {\n      const zai = await ZAI.create();\n\n      const response = await zai.images.generations.create({\n        prompt: prompt,\n        size: size\n      });\n\n      if (!response.data || !response.data[0] || !response.data[0].base64) {\n        throw new Error('Invalid response from image generation API');\n      }\n\n      const imageBase64 = response.data[0].base64;\n      const buffer = Buffer.from(imageBase64, 'base64');\n      fs.writeFileSync(outputPath, buffer);\n\n      return {\n        success: true,\n        path: outputPath,\n        attempts: attempt\n      };\n    } catch (error) {\n      lastError = error;\n      console.error(`Attempt ${attempt} failed:`, error.message);\n\n      if (attempt \u003C retries) {\n        \u002F\u002F Wait before retry (exponential backoff)\n        await new Promise(resolve => setTimeout(resolve, 1000 * attempt));\n      }\n    }\n  }\n\n  return {\n    success: false,\n    error: lastError.message,\n    attempts: retries\n  };\n}\n```\n\n## Common Use Cases\n\n1. **Website Design**: Generate hero images, backgrounds, and visual assets\n2. **Marketing Materials**: Create social media graphics and promotional images\n3. **Product Visualization**: Generate product mockups and variations\n4. **Content Creation**: Produce blog post illustrations and thumbnails\n5. **Brand Assets**: Create logos, icons, and brand imagery\n6. **UI\u002FUX Design**: Generate interface elements and illustrations\n7. **Game Development**: Create concept art and game assets\n8. **E-commerce**: Generate product images and lifestyle shots\n\n## Integration Examples\n\n### Express.js API Endpoint\n\n```javascript\nimport express from 'express';\nimport ZAI from 'z-ai-web-dev-sdk';\nimport fs from 'fs';\nimport path from 'path';\n\nconst app = express();\napp.use(express.json());\napp.use('\u002Fimages', express.static('generated-images'));\n\nlet zaiInstance;\nconst outputDir = '.\u002Fgenerated-images';\n\nasync function initZAI() {\n  zaiInstance = await ZAI.create();\n  if (!fs.existsSync(outputDir)) {\n    fs.mkdirSync(outputDir, { recursive: true });\n  }\n}\n\napp.post('\u002Fapi\u002Fgenerate-image', async (req, res) => {\n  try {\n    const { prompt, size = '1024x1024' } = req.body;\n\n    if (!prompt) {\n      return res.status(400).json({ error: 'Prompt is required' });\n    }\n\n    const response = await zaiInstance.images.generations.create({\n      prompt: prompt,\n      size: size\n    });\n\n    const imageBase64 = response.data[0].base64;\n    const buffer = Buffer.from(imageBase64, 'base64');\n    \n    const filename = `img_${Date.now()}.png`;\n    const filepath = path.join(outputDir, filename);\n    fs.writeFileSync(filepath, buffer);\n\n    res.json({\n      success: true,\n      imageUrl: `\u002Fimages\u002F${filename}`,\n      prompt: prompt,\n      size: size\n    });\n  } catch (error) {\n    res.status(500).json({\n      success: false,\n      error: error.message\n    });\n  }\n});\n\ninitZAI().then(() => {\n  app.listen(3000, () => {\n    console.log('Image generation API running on port 3000');\n  });\n});\n```\n\n## CLI Integration in Scripts\n\n### Shell Script Example\n\n```bash\n#!\u002Fbin\u002Fbash\n\n# Generate website assets using CLI\necho \"Generating website assets...\"\n\nz-ai image -p \"Modern tech hero banner, blue gradient\" -o \".\u002Fassets\u002Fhero.png\" -s 1440x720\nz-ai image -p \"Team collaboration illustration\" -o \".\u002Fassets\u002Fteam.png\" -s 1344x768\nz-ai image -p \"Simple geometric logo\" -o \".\u002Fassets\u002Flogo.png\" -s 1024x1024\n\necho \"Assets generated successfully!\"\n```\n\n## Troubleshooting\n\n**Issue**: \"SDK must be used in backend\"\n- **Solution**: Ensure z-ai-web-dev-sdk is only used in server-side code\n\n**Issue**: Invalid size parameter\n- **Solution**: Use only supported sizes: 1024x1024, 768x1344, 864x1152, 1344x768, 1152x864, 1440x720, 720x1440\n\n**Issue**: Generated image doesn't match prompt\n- **Solution**: Make prompts more specific and descriptive. Include style, details, and quality terms\n\n**Issue**: CLI command not found\n- **Solution**: Ensure z-ai CLI is properly installed and in PATH\n\n**Issue**: Image file is corrupted\n- **Solution**: Verify base64 decoding and file writing are correct\n\n## Prompt Engineering Tips\n\n### Good Prompts\n- ✓ \"Professional product photography of wireless headphones, white background, studio lighting, high quality\"\n- ✓ \"Mountain landscape at golden hour, oil painting style, dramatic clouds, detailed\"\n- ✓ \"Modern minimalist logo for tech company, blue and white, geometric shapes\"\n\n### Poor Prompts\n- ✗ \"headphones\"\n- ✗ \"picture of mountains\"\n- ✗ \"logo\"\n\n### Prompt Components\n1. **Subject**: What you want to see\n2. **Style**: Art style, photography style, etc.\n3. **Details**: Specific elements, colors, mood\n4. **Quality**: \"high quality\", \"detailed\", \"professional\"\n\n## Supported Image Sizes\n\n- `1024x1024` - Square\n- `768x1344` - Portrait\n- `864x1152` - Portrait\n- `1344x768` - Landscape\n- `1152x864` - Landscape\n- `1440x720` - Wide landscape\n- `720x1440` - Tall portrait\n\n## Remember\n\n- Always use z-ai-web-dev-sdk in backend code only\n- The SDK is already installed - import as shown\n- CLI tool is available for quick image generation\n- Supported sizes are specific - use the provided list\n- Base64 images need to be decoded before saving\n- Consider caching for repeated prompts\n- Implement retry logic for production applications\n- Use descriptive prompts for better results\n",{"name":5,"license":14,"description":7},"main","7ee19d9efa6123ac0eb02ec3f4a0382dc27e97ae","skills\u002Fimage-generation","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews","https:\u002F\u002Fgithub.com\u002Fnordeim","A freelance IT engineer","2026-06-24 17:56:29",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add nordeim\u002Fonestopnews --skill image-generation",{"tool":37,"command":38},"bunx","bunx skills add nordeim\u002Fonestopnews --skill image-generation",{"tool":40,"command":41},"pnpm","pnpm dlx skills add nordeim\u002Fonestopnews --skill image-generation","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fimage-generation\u002FSKILL.md",true,[45,50],{"path":46,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":49,"sourceHtmlUrl":15},"LICENSE.txt","LICENSE","许可证",1080,{"path":51,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":54,"sourceHtmlUrl":55},"scripts\u002Fimage-generation.ts","SCRIPT","脚本",813,"https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fimage-generation\u002Fscripts\u002Fimage-generation.ts",[57,66,74,82,89,97],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":61,"licenseFileUrl":62,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M75DXKQMDVYG9H9GP6SZSR02","webapp-testing","Web application testing principles. E2E, Playwright, deep audit strategies.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fwebapp-testing\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":70,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":19},"01M75DX35MS8HZ92CBW2Z9JYD3","web-search","Implement web search capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to search for real-time information from the web, retrieve up-to-date content beyond the knowledge cutoff, or find the latest news and data. Returns structured search results with URLs, snippets, and metadata.","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fweb-search\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fweb-search\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":78,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M75DWYHQ360A0TEKMNGN5S2H","web-reader","Implement web page content extraction capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to scrape web pages, extract article content, retrieve page metadata, or build applications that process web content. Supports automatic content extraction with title, HTML, and publication time retrieval.","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fweb-reader\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fweb-reader\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M75DWR41MFHYZWKZQW7W46VJ","web-frameworks","Build modern full-stack web applications with Next.js (App Router, Server Components, RSC, PPR, SSR, SSG, ISR), Turborepo (monorepo management, task pipelines, remote caching, parallel execution), and RemixIcon (3100+ SVG icons in outlined\u002Ffilled styles). Use when creating React applications, implementing server-side rendering, setting up monorepos with multiple packages, optimizing build performance and caching strategies, adding icon libraries, managing shared dependencies, or working with TypeScript full-stack projects.","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fweb-frameworks\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":93,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":19},"01M75DW8W3ZF2QX40KJYW47FGK","video-understand","Implement specialized video understanding capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to analyze video content, understand motion and temporal sequences, extract information from video frames, describe video scenes, or perform video-based AI analysis. Optimized for MP4, AVI, MOV, and other common video formats.","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fvideo-understand\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fvideo-understand\u002FSKILL.md",[],[],{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":101,"sourceHtmlUrl":102,"categories":103,"keywords":104,"publishedAt":19},"01M75DW3S2J8BT0BYNFNMMJMKD","video-generation","Implement AI-powered video generation capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to generate videos from text prompts or images, create video content programmatically, or build applications that produce video outputs. Supports asynchronous task management with status polling and result retrieval.","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fvideo-generation\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fnordeim\u002Fonestopnews\u002Fblob\u002Fmain\u002Fskills\u002Fvideo-generation\u002FSKILL.md",[],[]]