mcpField
N
nano-banana

nano-banana

github.com/rebyteai-template创意与媒体1767 次安装19 周前更新
代码仓库

关于 nano-banana

nano-banana 是通过 Google Nano Banana(Gemini 原生图像生成)按文本提示生成图像的技能,适用于需要快速草稿或高分辨率成品的创作流程。可选择 Flash 或 Pro,并设置输出比例与尺寸。

主要功能

  1. 01根据文本提示生成图像
  2. 02Flash 与 Pro 模型可选
  3. 03设置图像比例与尺寸
  4. 04返回 Base64 和数据 URL
  5. 05提供 Python 与 Node.js 示例

适用场景

  1. 01快速制作社交媒体图像
  2. 02生成最高 4K 的印刷素材
  3. 03为报告生成主题插图

安装

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

$npx skills add https://github.com/rebyteai-template/rebyte-skills --skill nano-banana

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

附带文件.gitignoreREADME.md

详细介绍

Nano Banana - 图像生成 API

使用 Google Nano Banana(Gemini 原生图像生成)根据文本提示词生成图像。

基础 URL

https://api.eng0.ai/api/data

模型

模型ID最适合最高分辨率
Flashflash快速生成、大批量任务1024px
Propro专业品质、复杂提示词4K

生成图像

根据文本描述创建图像。

curl -X POST https://api.eng0.ai/api/data/images/generate \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A futuristic cityscape at sunset with flying cars",
    "model": "flash",
    "aspectRatio": "16:9"
  }'

参数:

名称类型必填默认值描述
promptstring是-要生成图像的文本描述
modelstring否flashflash(快速,1024px)或 pro(高质量,最高 4K)
aspectRatiostring否1:1输出宽高比
imageSizestring否1K1K、2K 或 4K(仅 pro 模型支持 4K)

宽高比:

比例用途
1:1方形(社交媒体、图标)
16:9横向(演示文稿、横幅)
9:16纵向(移动设备、快拍)
4:3标准横向
3:4标准纵向
21:9超宽(电影风格)
2:3、3:2、4:5、5:4多种格式

响应:

{
  "image": {
    "base64": "iVBORw0KGgoAAAANSUhEUgAA...",
    "mimeType": "image/png",
    "dataUrl": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
  },
  "description": "A vibrant futuristic cityscape..."
}

响应字段:

字段描述
image.base64Base64 编码的图像数据
image.mimeType图像 MIME 类型(通常为 image/png)
image.dataUrl可直接用于 HTML/CSS 的数据 URL
description模型对生成图像的描述

常见工作流

生成简单图像
curl -X POST https://api.eng0.ai/api/data/images/generate \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A cute robot holding a cup of coffee"
  }'
生成高质量 4K 图像
curl -X POST https://api.eng0.ai/api/data/images/generate \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Professional product photo of a sleek smartphone on marble surface",
    "model": "pro",
    "imageSize": "4K",
    "aspectRatio": "4:3"
  }'
生成社交媒体横幅
curl -X POST https://api.eng0.ai/api/data/images/generate \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Abstract gradient background with geometric shapes in blue and purple",
    "aspectRatio": "16:9"
  }'
生成移动端快拍图像
curl -X POST https://api.eng0.ai/api/data/images/generate \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Cozy coffee shop interior with warm lighting",
    "aspectRatio": "9:16"
  }'

使用 Python

import requests
import base64
from pathlib import Path

BASE_URL = "https://api.eng0.ai/api/data"

def generate_image(
    prompt: str,
    model: str = "flash",
    aspect_ratio: str = "1:1",
    image_size: str = "1K"
) -> dict:
    """Generate an image from a text prompt."""
    response = requests.post(
        f"{BASE_URL}/images/generate",
        json={
            "prompt": prompt,
            "model": model,
            "aspectRatio": aspect_ratio,
            "imageSize": image_size
        }
    )
    return response.json()

def save_image(result: dict, filepath: str) -> None:
    """Save generated image to a file."""
    if "image" in result:
        image_data = base64.b64decode(result["image"]["base64"])
        Path(filepath).write_bytes(image_data)
        print(f"Saved to {filepath}")
    else:
        print(f"Error: {result.get('error', 'Unknown error')}")

# Example: Generate and save an image
result = generate_image(
    prompt="A serene mountain landscape at dawn with mist in the valley",
    aspect_ratio="16:9"
)
save_image(result, "landscape.png")

# Example: Generate high-quality product image
result = generate_image(
    prompt="Minimalist tech gadget on white background, studio lighting",
    model="pro",
    image_size="4K"
)
save_image(result, "product.png")

使用 Node.js

const fs = require('fs');

const BASE_URL = 'https://api.eng0.ai/api/data';

async function generateImage(prompt, options = {}) {
  const response = await fetch(`${BASE_URL}/images/generate`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      prompt,
      model: options.model || 'flash',
      aspectRatio: options.aspectRatio || '1:1',
      imageSize: options.imageSize || '1K'
    })
  });
  return response.json();
}

function saveImage(result, filepath) {
  if (result.image) {
    const buffer = Buffer.from(result.image.base64, 'base64');
    fs.writeFileSync(filepath, buffer);
    console.log(`Saved to ${filepath}`);
  } else {
    console.error('Error:', result.error || 'Unknown error');
  }
}

// Example usage
(async () => {
  const result = await generateImage(
    'A neon-lit cyberpunk street scene at night',
    { aspectRatio: '21:9' }
  );
  saveImage(result, 'cyberpunk.png');
})();

提示词技巧

描述具体
Bad:  "A dog"
Good: "A golden retriever puppy playing in autumn leaves, warm sunlight"
指定风格
"Oil painting style portrait of a woman in Renaissance clothing"
"Minimalist vector illustration of a mountain range"
"Photorealistic close-up of a dewdrop on a leaf"
指定光照
"... with dramatic side lighting"
"... golden hour sunlight"
"... soft diffused studio lighting"
补充背景信息
"... in the style of Studio Ghibli"
"... professional product photography"
"... vintage 1970s film aesthetic"

模型对比

特性FlashPro
速度快较慢
最高分辨率1024px4K
复杂提示词良好出色
文本渲染良好清晰
最适合快速迭代、预览最终素材、印刷

何时使用 Flash:

  • 快速原型设计
  • 社交媒体内容
  • 大批量生成
  • 需要速度时

何时使用 Pro:

  • 专业/商业用途
  • 印刷材料
  • 复杂构图
  • 注重质量时

错误处理

未生成图像:

{
  "error": "No image generated",
  "message": "SAFETY"
}

当提示词触发内容安全过滤器时会出现这种情况。

参数无效:

{
  "error": "Invalid parameters",
  "message": "Missing required parameter: prompt"
}

重要说明

  • 所有生成的图像都包含不可见的 SynthID 水印
  • 图像在服务端生成;Base64 响应可能很大
  • pro 模型耗时更长,但生成质量更高
  • 4K 分辨率仅适用于 pro 模型
  • 内容安全过滤器可能会拦截某些提示词

与其他技能结合使用

此技能提供图像生成功能。可与以下技能结合使用:

  • deep-research - 为研究报告生成插图
  • market-data - 创建金融数据可视化图像

示例工作流:

  1. 研究某个主题(deep-research)
  2. 生成相关插图(此技能)
  3. 汇编成报告

评论

支持 Markdown