mcpField
G
gemini-imagegen

gemini-imagegen

github.com/everyincクリエイティブ・メディア25.8k633 回インストール今日更新
リポジトリ

gemini-imagegen について

gemini-imagegenは、GoogleのGemini APIで画像を生成・編集するスキルです。モデル設定、画像サイズ、反復的な調整、生成画像ファイルの扱い方を説明します。

主な機能

  1. 01Gemini APIによる画像生成
  2. 02テキストプロンプトによる画像編集
  3. 03解像度とアスペクト比の設定
  4. 04チャットによる画像の反復調整
  5. 05Google Search groundingの利用

活用シーン

  1. 01文章のプロンプトから画像を生成
  2. 02会話形式で既存画像を修正
  3. 03指定したサイズと比率で画像を作成

インストール

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

$npx skills add https://github.com/everyinc/compound-engineering-plugin --skill gemini-imagegen

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

同梱ファイル

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

requirements.txt
scripts/
compose_images.py
edit_image.py
gemini_images.py
generate_image.py
multi_turn_chat.py

詳細

Gemini 画像生成(Nano Banana Pro)

Google の Gemini API を使用して画像を生成、編集します。環境変数 GEMINI_API_KEY を設定する必要があります。

デフォルトモデル

モデル解像度最適な用途
gemini-3-pro-image-preview1K-4Kすべての画像生成(デフォルト)

注: 常にこの Pro モデルを使用してください。明示的に指定された場合に限り、別のモデルを使用してください。

クイックリファレンス

デフォルト設定
  • モデル: gemini-3-pro-image-preview
  • 解像度: 1K(デフォルト。選択肢: 1K、2K、4K)
  • アスペクト比: 1:1(デフォルト)
利用可能なアスペクト比

1:1、2:3、3:2、3:4、4:3、4:5、5:4、9:16、16:9、21:9

利用可能な解像度

1K(デフォルト)、2K、4K

基本的な API パターン

import os
from google import genai
from google.genai import types

client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])

# Basic generation (1K, 1:1 - defaults)
response = client.models.generate_content(
    model="gemini-3-pro-image-preview",
    contents=["Your prompt here"],
    config=types.GenerateContentConfig(
        response_modalities=['TEXT', 'IMAGE'],
    ),
)

for part in response.parts:
    if part.text:
        print(part.text)
    elif part.inline_data:
        image = part.as_image()
        image.save("output.png")

カスタム解像度とアスペクト比

from google.genai import types

response = client.models.generate_content(
    model="gemini-3-pro-image-preview",
    contents=[prompt],
    config=types.GenerateContentConfig(
        response_modalities=['TEXT', 'IMAGE'],
        image_config=types.ImageConfig(
            aspect_ratio="16:9",  # Wide format
            image_size="2K"       # Higher resolution
        ),
    )
)
解像度の例
# 1K (default) - Fast, good for previews
image_config=types.ImageConfig(image_size="1K")

# 2K - Balanced quality/speed
image_config=types.ImageConfig(image_size="2K")

# 4K - Maximum quality, slower
image_config=types.ImageConfig(image_size="4K")
アスペクト比の例
# Square (default)
image_config=types.ImageConfig(aspect_ratio="1:1")

# Landscape wide
image_config=types.ImageConfig(aspect_ratio="16:9")

# Ultra-wide panoramic
image_config=types.ImageConfig(aspect_ratio="21:9")

# Portrait
image_config=types.ImageConfig(aspect_ratio="9:16")

# Photo standard
image_config=types.ImageConfig(aspect_ratio="4:3")

画像の編集

テキストプロンプトとともに既存の画像を渡します。

from PIL import Image

img = Image.open("input.png")
response = client.models.generate_content(
    model="gemini-3-pro-image-preview",
    contents=["Add a sunset to this scene", img],
    config=types.GenerateContentConfig(
        response_modalities=['TEXT', 'IMAGE'],
    ),
)

複数ターンでの調整

チャットを使って反復的に編集します。

from google.genai import types

chat = client.chats.create(
    model="gemini-3-pro-image-preview",
    config=types.GenerateContentConfig(response_modalities=['TEXT', 'IMAGE'])
)

response = chat.send_message("Create a logo for 'Acme Corp'")
# Save first image...

response = chat.send_message("Make the text bolder and add a blue gradient")
# Save refined image...

プロンプト作成のベストプラクティス

写実的なシーン

カメラの詳細を含めます。レンズの種類、照明、角度、雰囲気を指定します。

「写実的なクローズアップのポートレート、85mm レンズ、柔らかなゴールデンアワーの光、浅い被写界深度」

スタイライズされたアート

スタイルを明示します。

「幸せそうなレッサーパンダのカワイイ風ステッカー、太い輪郭線、セルシェーディング、白い背景」

画像内のテキスト

フォントスタイルと配置を明示します。

「『Daily Grind』の文字を、すっきりしたサンセリフ体、黒と白、コーヒー豆のモチーフで使ったロゴを作成」

製品モックアップ

照明の設定と表面を説明します。

「磨かれたコンクリートの上に置いた、スタジオ照明の商品写真、3 点ソフトボックス照明、45 度の角度」

高度な機能

Google 検索によるグラウンディング

リアルタイムデータに基づいて画像を生成します。

response = client.models.generate_content(
    model="gemini-3-pro-image-preview",
    contents=["Visualize today's weather in Tokyo as an infographic"],
    config=types.GenerateContentConfig(
        response_modalities=['TEXT', 'IMAGE'],
        tools=[{"google_search": {}}]
    )
)
複数の参照画像(最大 14 枚)

複数の素材の要素を組み合わせます。

response = client.models.generate_content(
    model="gemini-3-pro-image-preview",
    contents=[
        "Create a group photo of these people in an office",
        Image.open("person1.png"),
        Image.open("person2.png"),
        Image.open("person3.png"),
    ],
    config=types.GenerateContentConfig(
        response_modalities=['TEXT', 'IMAGE'],
    ),
)

重要:ファイル形式とメディアタイプ

重要: Gemini API はデフォルトで JPEG 形式の画像を返します。保存時には、メディアタイプの不一致を避けるため、必ず .jpg 拡張子を使用してください。

# CORRECT - Use .jpg extension (Gemini returns JPEG)
image.save("output.jpg")

# WRONG - Will cause "Image does not match media type" errors
image.save("output.png")  # Creates JPEG with PNG extension!
PNG への変換(必要な場合)

PNG 形式が特に必要な場合:

from PIL import Image

# Generate with Gemini
for part in response.parts:
    if part.inline_data:
        img = part.as_image()
        # Convert to PNG by saving with explicit format
        img.save("output.png", format="PNG")
画像形式の確認

file コマンドを使って、実際の形式と拡張子を確認します。

file image.png
# If output shows "JPEG image data" - rename to .jpg!

注意事項

  • 生成された画像にはすべて SynthID のウォーターマークが含まれます
  • Gemini はデフォルトで JPEG 形式を返します。必ず .jpg 拡張子を使用してください
  • 画像のみのモード(responseModalities: ["IMAGE"])は Google 検索によるグラウンディングと併用できません
  • 編集する場合は、変更内容を会話形式で説明してください。モデルはセマンティックマスキングを理解します
  • 速度を優先する場合はデフォルトの 1K 解像度を使用し、品質が重要な場合は 2K/4K を使用してください

コメント