mcpField
G
gemini-3-image-generation

gemini-3-image-generation

github.com/adaptationioクリエイティブ・メディア77 回インストール
リポジトリ

gemini-3-image-generation について

Gemini 3 Pro Image を使う開発者向けの画像生成ガイドスキルです。4K 出力、画像内の文字描画、Google Search に基づく生成、会話形式の編集を扱います。

主な機能

  1. 01プロンプトからの画像生成
  2. 02ネイティブ 4K とアップスケーリング
  3. 03画像内の文字描画
  4. 04Google Search に基づく生成
  5. 05複数ターンの会話形式編集
  6. 06カスタムアスペクト比

活用シーン

  1. 01プロンプトから画像を生成
  2. 02高解像度のビジュアル素材を作成
  3. 03読みやすい文字入りデザインを作成
  4. 04複数ターンで画像を調整

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/adaptationio/skrillz --skill gemini-3-image-generation

インストール後、Claude Code で/gemini-3-image-generationを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

references/
conversational-editing.md
generation-guide.md
grounded-generation.md
model-setup.md
pricing-optimization.md
resolution-guide.md
scripts/
edit-image.py
generate-image.py
grounded-gen.py

詳細

Gemini 3 Pro Image 画像生成(Nano Banana Pro)

Gemini 3 Pro Image(gemini-3-pro-image-preview)を使った画像生成の総合ガイドです。Nano Banana Pro としても知られています。このスキルは画像出力(画像の生成)に焦点を当てています。入力(画像の分析)については、gemini-3-multimodal を参照してください。

概要

Gemini 3 Pro Image(Nano Banana Pro 🍌)は、ネイティブの 4K 対応、画像内のテキスト描画、Google Search を使ったグラウンディング生成、会話形式の編集機能を備えた Google の画像生成モデルです。

主な機能
  • 4K 解像度: ネイティブの 4K 生成と、2K/4K へのアップスケーリング
  • テキスト描画: 画像内に高品質なテキストを描画
  • グラウンディング生成: Google Search を使って事実確認された画像を生成
  • 会話形式の編集: コンテキストを維持しながら複数ターンにわたって画像を編集
  • アスペクト比: 4K で 16:9 やカスタム比率に対応
  • 品質管理: 生成パラメーターを細かく調整可能
このスキルを使用する場面
  • テキストプロンプトから画像を生成する
  • 4K 解像度の画像を作成する
  • 画像内にテキストを描画する
  • 事実確認された画像を生成する(グラウンディング)
  • 会話形式で画像を編集する
  • 複数ターンにわたって画像を調整する
  • カスタムのアスペクト比で画像を生成する

クイックスタート

前提条件
  • Gemini API のセットアップ(gemini-3-pro-api スキルを参照)
  • モデル: gemini-3-pro-image-preview
Python クイックスタート
import google.generativeai as genai

genai.configure(api_key="YOUR_API_KEY")

# Use the image generation model
model = genai.GenerativeModel("gemini-3-pro-image-preview")

# Generate image
response = model.generate_content("A serene mountain landscape at sunset")

# Save image
if response.parts:
    with open("generated_image.png", "wb") as f:
        f.write(response.parts[0].inline_data.data)
    print("Image saved!")
Node.js クイックスタート
import { GoogleGenerativeAI } from "@google/generative-ai";
import fs from "fs";

const genAI = new GoogleGenerativeAI("YOUR_API_KEY");
const model = genAI.getGenerativeModel({ model: "gemini-3-pro-image-preview" });

const result = await model.generateContent("A serene mountain landscape at sunset");
const imageData = result.response.parts[0].inlineData.data;

fs.writeFileSync("generated_image.png", Buffer.from(imageData, "base64"));
console.log("Image saved!");

主なタスク

タスク 1:テキストプロンプトから画像を生成する

目標: テキストによる説明から高品質な画像を作成します。

Python の例:

import google.generativeai as genai

genai.configure(api_key="YOUR_API_KEY")

model = genai.GenerativeModel(
    "gemini-3-pro-image-preview",
    generation_config={
        "thinking_level": "high",  # Best quality
        "temperature": 1.0
    }
)

# Generate image
prompt = """A futuristic cityscape at night with:
- Neon lights and holographic advertisements
- Flying vehicles
- Tall skyscrapers with unique architecture
- Rain-slicked streets reflecting the lights
- Cinematic, detailed, 4K quality"""

response = model.generate_content(prompt)

# Save image
if response.parts and hasattr(response.parts[0], 'inline_data'):
    image_data = response.parts[0].inline_data.data
    with open("futuristic_city.png", "wb") as f:
        f.write(image_data)
    print("Image generated successfully!")
else:
    print("No image generated")

より良いプロンプトを作成するためのヒント:

  • 具体的で詳細に記述する
  • アートスタイル(リアル、漫画、油絵など)を指定する
  • 照明、雰囲気、ムードを含める
  • 品質レベル(4K、詳細、高品質など)を指定する
  • 色、質感、構図を説明する

参照: プロンプト作成の詳細な手法については、references/generation-guide.md を参照してください。


タスク 2:4K 画像を生成する

目標: アップスケーリングにより、高解像度の 4K 画像を作成します。

Python の例:

# Generate with 4K quality specification
prompt = """A photorealistic portrait of a scientist in a modern lab:
- 4K ultra-high definition
- Sharp focus on subject
- Soft bokeh background
- Professional studio lighting
- Fine detail in textures
- Cinema-grade quality"""

response = model.generate_content(prompt)

# 4K image will be generated
if response.parts:
    with open("scientist_4k.png", "wb") as f:
        f.write(response.parts[0].inline_data.data)

4K の機能:

  • ネイティブの 4K 解像度に対応
  • 2K/4K へのアップスケーリング
  • 4K で 16:9 のアスペクト比に対応
  • 細部と鮮明さを強化

参照: 解像度の制御については、references/resolution-guide.md を参照してください。


タスク 3:画像内にテキストを描画する

目標: 読みやすく、高品質なテキストを含む画像を生成します。

Python の例:

prompt = """Create a professional business card design with:
- Company name: "TechVision AI"
- Text: "Dr. Sarah Chen"
- Text: "Chief AI Officer"
- Text: "[email protected]"
- Text: "+1 (555) 123-4567"
- Modern, clean design
- Professional fonts
- Blue and white color scheme
- All text clearly readable"""

response = model.generate_content(prompt)

if response.parts:
    with open("business_card.png", "wb") as f:
        f.write(response.parts[0].inline_data.data)

テキスト描画のベストプラクティス:

  • 描画するテキストを引用符で囲んで明示する
  • 「読みやすい」または「はっきり見える」テキストを指定する
  • テキストは短く、シンプルにする
  • 必要に応じてフォントスタイルを指定する
  • コントラストの高い背景を使用する

参照: テキスト描画の手法については、references/generation-guide.md を参照してください。


タスク 4:グラウンディング生成(事実確認された画像)

目標: Google Search のグラウンディングを利用して、事実に即した画像を生成します。

Python の例:

# Enable Google Search grounding for factual accuracy
model_grounded = genai.GenerativeModel(
    "gemini-3-pro-image-preview",
    tools=[{"google_search_retrieval": {}}]  # Enable grounding
)

prompt = """Generate an accurate image of the International Space Station
with Earth in the background. Use current ISS configuration."""

response = model_grounded.generate_content(prompt)

if response.parts:
    with open("iss_grounded.png", "wb") as f:
        f.write(response.parts[0].inline_data.data)

    # Check if grounding was used
    if hasattr(response, 'grounding_metadata'):
        print(f"Grounding sources used: {len(response.grounding_metadata.grounding_chunks)}")

グラウンディング生成のユースケース:

  • 歴史的な情景(時代考証に正確なもの)
  • 科学的な視覚化
  • 時事問題
  • 有名なランドマーク
  • 製品の表現

メリット:

  • 事実の正確性
  • 現実世界に基づいた生成
  • ハルシネーションの低減
  • 最新情報の反映

注: Google Search の無料利用枠を使用します(1 日あたり 1,500 クエリ)。

参照: 詳細なガイドについては、references/grounded-generation.md を参照してください。


タスク 5:会話形式の画像編集

目標: 複数ターンの会話を通じて、画像を段階的に調整します。

Python の例:

model = genai.GenerativeModel("gemini-3-pro-image-preview")

# Start a chat session for conversational editing
chat = model.start_chat()

# First generation
response1 = chat.send_message("Create a cozy coffee shop interior")

if response1.parts:
    with open("coffee_shop_v1.png", "wb") as f:
        f.write(response1.parts[0].inline_data.data)

# Refine the image
response2 = chat.send_message("Add more plants and warm lighting")

if response2.parts:
    with open("coffee_shop_v2.png", "wb") as f:
        f.write(response2.parts[0].inline_data.data)

# Further refinement
response3 = chat.send_message("Make it more minimalist, remove some decorations")

if response3.parts:
    with open("coffee_shop_v3.png", "wb") as f:
        f.write(response3.parts[0].inline_data.data)

会話形式の編集機能:

  • ターンをまたいで視覚的なコンテキストを維持する
  • 段階的に変更する
  • 自然言語で指示する
  • 複数ターンにわたって調整する
  • コンテキストに応じて変更する

編集コマンドの例:

  • 「もっと暗く/明るくして」
  • 「[要素]をもっと追加して」
  • 「配色を[色]に変更して」
  • 「もっとリアルに/芸術的にして」
  • 「[要素]を削除して」

参照: 応用的なパターンについては、references/conversational-editing.md を参照してください。


Task 6: カスタムアスペクト比

目標: 特定のアスペクト比で画像を生成します。

Python の例:

# 16:9 aspect ratio (4K supported)
prompt_169 = "A cinematic landscape in 16:9 aspect ratio, 4K quality"

# Square aspect ratio
prompt_square = "A square logo design for a tech company"

# Portrait orientation
prompt_portrait = "A portrait-oriented movie poster"

response = model.generate_content(prompt_169)
# Image will be generated in specified ratio

対応する比率:

  • 16:9 - ワイド、シネマティック(4K 対応)
  • 1:1 - 正方形
  • 4:3 - 標準
  • 9:16 - 縦向き/ポートレート

Task 7: 画像生成コストの最適化

目標: 画像生成の品質とコストのバランスを取ります。

料金:

  • テキスト入力: 100 万トークンあたり $1-2
  • テキスト出力: 100 万トークンあたり $6-9
  • 画像出力: 1 枚あたり $0.134(解像度によって異なります)

Python によるコスト最適化:

def generate_with_cost_tracking(prompt):
    """Generate image and track costs"""

    response = model.generate_content(prompt)

    # Calculate cost
    usage = response.usage_metadata
    input_cost = (usage.prompt_token_count / 1_000_000) * 2.00
    output_cost = (usage.candidates_token_count / 1_000_000) * 9.00
    image_cost = 0.134  # Per image

    total_cost = input_cost + output_cost + image_cost

    print(f"Input tokens: {usage.prompt_token_count} (${input_cost:.6f})")
    print(f"Output tokens: {usage.candidates_token_count} (${output_cost:.6f})")
    print(f"Image cost: ${image_cost:.6f}")
    print(f"Total: ${total_cost:.6f}")

    return response

response = generate_with_cost_tracking("A beautiful sunset over mountains")

コスト最適化の戦略:

  1. リクエストをバッチ処理する: 1 回のセッションで複数の画像を生成します
  2. チャットセッションを再利用する: 会話形式の編集はより効率的です
  3. 具体的なプロンプトを使う: 明確なプロンプトにより再生成の必要性を減らせます
  4. 使用状況を監視する: プロジェクトごとのコストを追跡します
  5. 適切な品質を選ぶ: すべての画像に 4K が必要なわけではありません

詳細な戦略については、 references/pricing-optimization.md を参照してください


画像のバッチ生成

import google.generativeai as genai

genai.configure(api_key="YOUR_API_KEY")
model = genai.GenerativeModel("gemini-3-pro-image-preview")

prompts = [
    "A serene mountain lake at dawn",
    "A bustling market in Morocco",
    "A futuristic robot assistant",
    "An abstract geometric pattern"
]

for i, prompt in enumerate(prompts):
    print(f"Generating image {i+1}/{len(prompts)}: {prompt}")

    response = model.generate_content(prompt)

    if response.parts:
        with open(f"generated_{i+1}.png", "wb") as f:
            f.write(response.parts[0].inline_data.data)
        print(f"  Saved: generated_{i+1}.png")

エラー処理

from google.api_core import exceptions

def safe_image_generation(prompt):
    """Generate image with error handling"""

    try:
        response = model.generate_content(prompt)

        if not response.parts:
            return {"success": False, "error": "No image generated"}

        if not hasattr(response.parts[0], 'inline_data'):
            return {"success": False, "error": "Invalid response format"}

        return {
            "success": True,
            "image_data": response.parts[0].inline_data.data,
            "mime_type": response.parts[0].inline_data.mime_type
        }

    except exceptions.InvalidArgument as e:
        return {"success": False, "error": f"Invalid prompt: {e}"}
    except exceptions.ResourceExhausted as e:
        return {"success": False, "error": f"Rate limit exceeded: {e}"}
    except Exception as e:
        return {"success": False, "error": f"Error: {e}"}

参考資料

基本ガイド

最適化

スクリプト

公式リソース


関連スキル

  • gemini-3-pro-api - 基本的なセットアップ、認証、テキスト生成
  • gemini-3-multimodal - 画像入力(画像の分析)
  • gemini-3-advanced - 高度な機能(キャッシュ、バッチ処理、ツール)

ベストプラクティス

  1. 具体的に指定する: 詳細なプロンプトほど、より良い結果が得られます
  2. 品質を指定する: 4K または高品質を明示的に指定します
  3. グラウンディングを使う: 事実の正確性を高めるために有効にします
  4. 会話形式で反復する: 調整にはチャットを使います
  5. コストを監視する: 特に 4K の使用状況を追跡します
  6. エラーに対処する: 再試行ロジックを実装します
  7. 画像を適切に保存する: 書き込みにはバイナリモードを使います

トラブルシューティング

問題:画像が生成されない

解決策: response.parts が存在し、inline_data 属性があることを確認します

問題:画像の品質が低い

解決策: プロンプトに「4K」「高品質」「詳細」を追加します

問題:画像内のテキストが読めない

解決策: テキストを引用符で囲んで明示し、「読みやすいテキスト」をリクエストします

問題:画像の事実が不正確

解決策: Google 検索を使ったグラウンディング生成を有効にします

問題:コストが高い

解決策: プロンプトを最適化し、リクエストをバッチ処理して、使用状況を監視します


まとめ

このスキルでは、画像生成の機能を一通り利用できます。

✅ テキストから画像を生成 ✅ ネイティブな 4K 対応 ✅ 画像内のテキスト描画 ✅ グラウンディング生成(事実確認済み) ✅ 会話形式の編集 ✅ カスタムアスペクト比 ✅ コスト最適化 ✅ 本番環境対応のサンプル

画像生成を始めますか? まずは上記のタスク 1「テキストプロンプトから画像を生成」から始めてください!

コメント