mcpField
G
generate-image

generate-image

github.com/richardanaya创意与媒体85 次安装
代码仓库

关于 generate-image

generate-image 是一项技能,通过 fal.ai MCP 网关调用 xAI 的 Grok Imagine,将文本描述生成图像。可设置图像数量、宽高比和输出格式。

主要功能

  1. 01文本生成图像
  2. 02设置生成数量
  3. 03支持多种宽高比
  4. 04支持 JPEG、PNG 和 WebP
  5. 05返回修订后的提示词

适用场景

  1. 01根据描述创作插画
  2. 02生成肖像或概念艺术
  3. 03按指定宽高比生成图像

MCP 相关

通过 fal.ai MCP 网关搜索图像模型,并运行 xAI Grok Imagine 端点。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/richardanaya/agent-skills --skill generate-image

安装后在 Claude Code 中输入/generate-image确认已加载。

详细介绍

生成图像技能

描述

通过 fal.ai MCP 网关使用 xAI 的 Grok Imagine 生成图像。此技能支持通过详细提示词生成照片级真实、艺术风格和风格化图像。

使用时机

当用户希望:

  • 根据文本描述生成图像
  • 创作插画、艺术作品或视觉内容
  • 使用 AI 图像生成工具
  • 制作概念艺术、肖像、场景或抽象图像

前置条件

确保 MCP 服务已连接且 fal.ai 服务可用:

mcp({})  // Check server status

输入模式

参数类型必需默认值描述
promptstring是-对所需图像的文本描述
num_imagesinteger否1要生成的图像数量
aspect_ratioAspectRatioEnum否"1:1"生成图像的宽高比
output_formatOutputFormatEnum否"jpeg"生成图像的格式
sync_modeboolean否false若为 true,则以 data URI 形式返回媒体
AspectRatioEnum 值
值描述
"2:1"超宽全景
"20:9"电影级超宽
"19.5:9"手机超宽
"16:9"HD 宽屏(视频标准)
"4:3"经典显示比例
"3:2"照片打印比例
"1:1"正方形(默认)
"2:3"竖版照片
"3:4"竖版显示
"9:16"手机竖屏
"9:19.5"手机长屏
"9:20"手机超长屏
"1:2"竖向全景
OutputFormatEnum 值
值描述
"jpeg"JPEG 格式(默认,压缩效果最佳)
"png"PNG 格式(无损,支持透明度)
"webp"WebP 格式(针对现代网页优化)

输出模式

字段类型描述
imageslist生成的图像对象数组
revised_promptstring模型使用的增强版提示词
ImageFile 对象
字段类型描述
urlstring生成图像的网址

工具

1. 搜索图像生成模型

首先,确认可用的图像生成模型:

mcp({
  search: "image generation",
  server: "fal"
})

或者专门搜索 Grok:

mcp({
  search: "grok",
  server: "fal"
})
2. 生成图像

使用 fal_run_model 工具和 xai/grok-imagine-image 端点:

mcp({
  tool: "fal_run_model",
  server: "fal",
  args: {
    "endpoint_id": "xai/grok-imagine-image",
    "input": {
      "prompt": "Your detailed image description here",
      "num_images": 1,
      "aspect_ratio": "1:1",
      "output_format": "jpeg"
    }
  }
})
3. 显示图像

生成后,向用户显示图像:

show_image({
  url: "https://v3b.fal.media/files/.../image.jpg"
})

或者显示本地文件:

show_image({
  path: "/path/to/local/image.png"
})

请求示例

{
  "prompt": "Abstract human silhouette, golden particles ready to burst outward representing joy, data visualization style, emotional expression through particles, artistic scientific",
  "num_images": 1,
  "aspect_ratio": "1:1",
  "output_format": "jpeg"
}

响应示例

{
  "images": [
    {
      "url": "https://v3b.fal.media/files/b/0a8b90b7/9avg_nKJmcVinjQHJR_Ja.jpg"
    }
  ],
  "revised_prompt": ""
}

最佳实践

撰写有效的提示词
  1. 具体明确:包含主体、风格、光线、氛围和质量描述
  2. 使用艺术风格参考:例如“电影级光线”“照片级真实”“油画”“动漫风格”
  3. 指定技术质量:例如“8k 分辨率”“细节丰富”“焦点清晰”
  4. 描述构图:例如“特写肖像”“广阔风景”“鸟瞰图”
  5. 包含情绪/氛围:例如“戏剧性”“宁静”“未来感”“复古”
各类别提示词示例

肖像:

Portrait of a wise elderly wizard with flowing white beard, wearing intricate 
blue robes embroidered with silver stars, mystical library background, warm 
candlelight, highly detailed face, 8k, photorealistic

科幻:

Futuristic cyberpunk city at night, neon signs in Japanese, flying cars, rain 
streets reflecting lights, towering holographic advertisements, blade runner 
style, cinematic composition, 8k quality

自然:

Majestic snow-capped mountains at golden hour, crystal clear alpine lake with 
reflection, pine forest in foreground, dramatic clouds, landscape photography 
style, ultra detailed, 8k resolution

抽象:

Abstract human silhouette, golden particles ready to burst outward representing 
joy, data visualization style, emotional expression through particles, 
artistic scientific

角色(例如 Ferengi):

A Star Trek Ferengi alien, humanoid with large ears, wrinkled forehead, sharp 
teeth grin, wearing traditional Ferengi business attire with dark tunic and 
collared shirt, standing in a sci-fi alien marketplace, detailed facial features, 
dramatic lighting, cinematic quality, 8k resolution, photorealistic

完整工作流示例

以下是生成并显示图像的完整工作流:

// Step 1: Generate the image
const result = await mcp({
  tool: "fal_run_model",
  server: "fal",
  args: {
    "endpoint_id": "xai/grok-imagine-image",
    "input": {
      "prompt": "A serene Japanese zen garden with raked sand patterns, moss-covered stones, cherry blossom tree in bloom, morning mist, tranquil atmosphere, traditional wooden pagoda in background, ultra detailed, 8k, photorealistic",
      "num_images": 1,
      "aspect_ratio": "16:9",
      "output_format": "jpeg"
    }
  }
});

// Step 2: Extract the image URL
const imageUrl = result.result.images[0].url;

// Step 3: Display to user
show_image({
  url: imageUrl
});

故障排除

问题解决方案
找不到模型运行 mcp({ search: "grok", server: "fal" }) 验证端点
连接错误使用 mcp({}) 检查 MCP 状态并重新连接
图像质量不佳在提示词中添加更具体的描述
宽高比错误使用 "1:1"、"16:9"、"9:16"、"4:3" 或 "3:4"
生成超时尝试更简单的提示词,或检查 fal.ai 状态
同步模式无法工作设置 "sync_mode": true 以输出 data URI

替代模型

如果 Grok Imagine 不可用,可以搜索替代模型:

mcp({
  search: "flux",
  server: "fal"
})

热门替代模型:

  • fal-ai/flux-2-pro - 高质量、细节丰富的图像
  • fal-ai/flux/dev - 生成速度快,质量良好
  • fal-ai/flux-1/schnell - 推理速度最快

注意事项

  • 生成的图像会暂时托管在 fal.media 上
  • 图像 URL 的有效期有限(通常为 24-48 小时)
  • 如需永久存储,请将图像保存到本地
  • 生成图像时,请注意内容政策
  • revised_prompt 字段可能包含经过增强的提示词

评论

支持 Markdown