ce-gemini-imagegen について
ce-gemini-imagegen は、Google's Gemini API で画像を生成・編集するエージェントスキルです。サイズやアスペクト比の設定、参照画像、チャットでの反復調整、検索結果に基づく生成に対応します。
主な機能
- 01画像の生成と編集
- 02サイズとアスペクト比の設定
- 03複数の参照画像の利用
- 04チャットによる反復調整
- 05Google Search grounding 対応
活用シーン
- 01テキストプロンプトから画像を作成
- 02既存画像の編集
- 03チャットで画像を段階的に調整
- 04最新情報に基づくビジュアル生成
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ everyinc/ compound-engineering-plugin --skill ce-gemini-imagegenインストール後、Claude Code で/ce-gemini-imagegenを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
requirements.txtscripts/compose_images.pyedit_image.pygemini_images.pygenerate_image.pymulti_turn_chat.py詳細
Gemini 画像生成(Nano Banana Pro)
Google の Gemini API を使用して画像を生成、編集します。環境変数 GEMINI_API_KEY を設定する必要があります。
デフォルトモデル
| モデル | 解像度 | 最適な用途 |
|---|---|---|
gemini-3-pro-image-preview | 1K-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 を使用してください