Nano Banana (การสร้างรูปภาพ)

Nano Banana คือชื่อของความสามารถในการสร้างรูปภาพดั้งเดิมของ Gemini ปัจจุบันโมเดลนี้หมายถึงโมเดล 2 รายการที่แตกต่างกันซึ่งพร้อมใช้งานใน Gemini API ดังนี้

  • Nano Banana: โมเดลรูปภาพ Gemini 2.5 Flash (gemini-2.5-flash-image) โมเดลนี้ออกแบบมาเพื่อความเร็วและประสิทธิภาพ โดยได้รับการเพิ่มประสิทธิภาพสำหรับงานที่มีปริมาณมากและมีความหน่วงต่ำ
  • Nano Banana Pro: โมเดลตัวอย่างรูปภาพของ Gemini 3 Pro (gemini-3-pro-image-preview) โมเดลนี้ออกแบบมาเพื่อการผลิตชิ้นงานระดับมืออาชีพ โดยใช้การให้เหตุผลขั้นสูง ("การคิด") เพื่อทำตามคำสั่งที่ซับซ้อนและแสดงข้อความที่มีความเที่ยงตรงสูง

เริ่มต้นใช้งาน

คุณสร้างรูปภาพโดยใช้generate_contentได้โดยใช้ชื่อโมเดลที่สอดคล้องกับเวอร์ชันที่คุณต้องการใช้

Python

from google import genai
from PIL import Image

client = genai.Client()

response = client.models.generate_content(
    model="gemini-2.5-flash-image",
    contents="Create a picture of a futuristic banana with neon lights in a cyberpunk city.",
)

for part in response.parts:
    if part.inline_data:
        image = part.as_image()
        image.show()

JavaScript

import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";

const ai = new GoogleGenAI({});

const response = await ai.models.generateContent({
  model: "gemini-2.5-flash-image",
  contents: "Create a picture of a futuristic banana with neon lights in a cyberpunk city.",
});

for (const part of response.candidates[0].content.parts) {
  if (part.inlineData) {
    const buffer = Buffer.from(part.inlineData.data, "base64");
    fs.writeFileSync("banana.png", buffer);
  }
}

Go

package main

import (
    "context"
    "os"
    "google.golang.org/genai"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        // handle error
    }

    resp, err := client.Models.GenerateContent(
        ctx,
        "gemini-2.5-flash-image",
        genai.Text("Create a picture of a futuristic banana with neon lights in a cyberpunk city."),
    )

    for _, part := range resp.Candidates[0].Content.Parts {
        if part.InlineData != nil {
            _ = os.WriteFile("banana.png", part.InlineData.Data, 0644)
        }
    }
}

Java

import com.google.genai.Client;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.Part;
import java.nio.file.Files;
import java.nio.file.Paths;

public class ImageGen {
  public static void main(String[] args) throws Exception {
    try (Client client = new Client()) {
      GenerateContentResponse response = client.models.generateContent(
          "gemini-2.5-flash-image",
          "Create a picture of a futuristic banana with neon lights in a cyberpunk city.",
          null);

      for (Part part : response.parts()) {
        if (part.inlineData().isPresent()) {
           Files.write(Paths.get("banana.png"), part.inlineData().get().data().get());
        }
      }
    }
  }
}

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [
        {"text": "Create a picture of a futuristic banana with neon lights in a cyberpunk city."}
      ]
    }]
  }'

ดูข้อมูลเพิ่มเติม

ดูเอกสารประกอบที่ครอบคลุมเกี่ยวกับการสร้างรูปภาพ การแก้ไข การแจ้งขั้นสูง และการเปรียบเทียบโมเดลได้ในคำแนะนำฉบับเต็ม