見出し画像

Gemini 2.5 Flash Image (nano-banana) プロンプトガイド

以下の記事が面白かったので、簡単にまとめました。

Image generation with Gemini


1. Geminiによる画像生成

「Gemini」は会話形式で画像を生成・処理できます。テキスト、画像、あるいはその両方を「Gemini」に指示することで、これまでにない高度な制御で画像を作成・編集・反復処理できます。

・テキスト to 画像
単純または複雑なテキストの説明から高品質の画像を生成します。

・画像 + テキスト to イメージ (編集)
画像を提供し、テキスト プロンプトを使用して要素を追加、削除、または変更したり、スタイルを変更したり、カラー グレーディングを調整したりします。

・マルチ画像 to 画像 (合成とスタイル転送)
複数の入力画像を使用して新しいシーンを合成したり、ある画像から別の画像にスタイルを転送したりします。

・反復的な改良
会話に参加して、複数回にわたって画像を徐々に改良し、完璧になるまで小さな調整を加えます。

・高忠実度のテキストレンダリング
読みやすく適切に配置されたテキストを含む画像を正確に生成します。ロゴ、図、ポスターに最適です。

生成されたすべての画像には「SynthID 透かし」が含まれます。

2. セットアップ

「Google Colab」での「Gemini API」のセットアップ手順は、次のとおりです。

(1) パッケージのインストール。

# パッケージのインストール
!pip install google-genai

(2) 「Google AI Studio」からAPIキーを取得し、Colabのシークレットマネージャーに登録。
キーは「GOOGLE_API_KEY」とします。

from google.colab import userdata

# 環境変数の準備 (左端の鍵アイコンでGOOGLE_API_KEYを設定)
GOOGLE_API_KEY = userdata.get("GOOGLE_API_KEY")

(3) クライアントの準備。

from google import genai

# クライアントの準備
client = genai.Client(api_key=GOOGLE_API_KEY)

3. テキスト to 画像

(1) 画像生成。

from google.genai import types
from PIL import Image
from io import BytesIO

# プロンプトの準備
prompt = (
    "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"
)

# 画像生成
response = client.models.generate_content(
    model="gemini-2.5-flash-image-preview",
    contents=[prompt],
)

# 画像出力
for part in response.candidates[0].content.parts:
    if part.text is not None:
        print(part.text)
    elif part.inline_data is not None:
        image = Image.open(BytesIO(part.inline_data.data))
        image.save("generated_image.png")

Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme

【翻訳】
Geminiをテーマにした高級レストランのnano-banana料理の写真を作成します


4.画像 + テキスト to 画像 (編集)

(1) 画像生成。

・cat_image.png

from google.genai import types
from PIL import Image
from io import BytesIO

# プロンプトの準備
prompt = (
    "Create a picture of my cat eating a nano-banana in a "
    "fancy restaurant under the Gemini constellation",
)

# 画像の準備
image = Image.open("cat_image.png")

# 画像生成
response = client.models.generate_content(
    model="gemini-2.5-flash-image-preview",
    contents=[prompt, image],
)

# 画像出力
for part in response.candidates[0].content.parts:
    if part.text is not None:
        print(part.text)
    elif part.inline_data is not None:
        image = Image.open(BytesIO(part.inline_data.data))
        image.save("generated_image.png")

Create a picture of my cat eating a nano-banana in a fancy restaurant under the Gemini constellation

【翻訳】
Geminiの高級レストランでnano-bananaを食べている猫の絵を描いてください

5. その他の画像生成モード

「Gemini」は、プロンプトの構造とコンテキストに基づいて、次のような他の画像インタラクションモードもサポートしています。

・テキスト to 画像 + テキスト (インターリーブ)
関連するテキストを含む画像を出力します。
【プロンプト例】「パエリアのイラスト付きレシピを生成します。」

・画像 + テキスト to 画像 + テキスト (インターリーブ)
画像とテキストを使用して、関連する新しい画像とテキストを作成します。
【プロンプト例】 (家具付きの部屋の画像付き)「私のスペースには他にどんな色のソファが合うでしょうか? 画像を更新できますか?」

・マルチターン画像編集 (チャット)
会話しながら画像の生成と編集を続けます。
【プロンプト例】「青い車の画像をアップロードしてください。」「この車をコンバーチブルに変えてください。」「今度は色を黄色に変えてください。」

6. プロンプトガイド

Gemini 2.5 Flash Image」の画像生成をマスターするには、まず1つの基本原則から始めます。

キーワードを羅列するのではなく、シーンを描写しましょう。 このモデルの強みは、深い言語理解力にあります。物語的で描写的な段落は、断片的な単語の羅列よりも、より優れた、より一貫性のあるイメージを生み出すことがほとんどです。

6-1. 画像生成のプロンプト

次の戦略は、探している画像を正確に生成するための効果的なプロンプトを作成するのに役立ちます。

(1) フォトリアリスティックなシーン
リアルな画像を作るには、写真用語を使いましょう。カメラアングル、レンズの種類、照明、細部までこだわることで、モデルを写真のようなリアルな仕上がりに近づけることができます。

・テンプレート

A photorealistic [shot type] of [subject], [action or expression], set in
[environment]. The scene is illuminated by [lighting description], creating
a [mood] atmosphere. Captured with a [camera/lens details], emphasizing
[key textures and details]. The image should be in a [aspect ratio] format.

【プロンプト例】

A photorealistic close-up portrait of an elderly Japanese ceramicist with
deep, sun-etched wrinkles and a warm, knowing smile. He is carefully
inspecting a freshly glazed tea bowl. The setting is his rustic,
sun-drenched workshop. The scene is illuminated by soft, golden hour light
streaming through a window, highlighting the fine texture of the clay.
Captured with an 85mm portrait lens, resulting in a soft, blurred background
(bokeh). The overall mood is serene and masterful. Vertical portrait
orientation.

太陽に深く刻まれた皺と、温かく物知り顔の笑みを浮かべた、年老いた日本人陶芸家の写実的なクローズアップポートレート。彼は、釉薬をかけたばかりの茶碗を注意深く見ています。舞台は、日差しが降り注ぐ素朴な工房です。窓から差し込む柔らかな黄金色の光が、土の繊細な質感を際立たせています。85mmのポートレートレンズで撮影されたため、背景は柔らかくぼやけています(ボケ)。全体的に穏やかで、見事な雰囲気です。縦位置ポートレート。

(2) 様式化されたイラストとステッカー
ステッカー、アイコン、アセットを作成するには、スタイルを明示的に指定し、透明な背景をリクエストします。

・テンプレート

A [style] sticker of a [subject], featuring [key characteristics] and a
[color palette]. The design should have [line style] and [shading style].
The background must be transparent.

【プロンプト例】

A kawaii-style sticker of a happy red panda wearing a tiny bamboo hat. It's
munching on a green bamboo leaf. The design features bold, clean outlines,
simple cel-shading, and a vibrant color palette. The background must be white.

小さな竹の帽子をかぶった幸せそうなレッサーパンダの、かわいいステッカーです。緑の竹の葉をむしゃむしゃ食べています。大胆ですっきりとしたアウトライン、シンプルなセルシェーディング、鮮やかなカラーパレットが特徴です。背景は白のみとなります。

(3) 画像内の正確なテキスト
「Gemini」はテキストのレンダリングに優れています。テキスト、フォントスタイル (説明的に)、そして全体的なデザインを明確にしましょう。

・テンプレート

Create a [image type] for [brand/concept] with the text "[text to render]"
in a [font style]. The design should be [style description], with a
[color scheme].

【プロンプト例】

Create a modern, minimalist logo for a coffee shop called 'The Daily Grind'.
The text should be in a clean, bold, sans-serif font. The design should
feature a simple, stylized icon of a a coffee bean seamlessly integrated
with the text. The color scheme is black and white.

「The Daily Grind」というコーヒーショップの、モダンでミニマルなロゴを作成してください。
テキストは、クリーンで太字のサンセリフフォントを使用してください。デザインは、テキストとシームレスに統合された、シンプルでスタイリッシュなコーヒー豆のアイコンを特徴としています。カラースキームは白黒です。

(4) 製品のモックアップと商業写真
電子商取引、広告、ブランディング用のクリーンでプロフェッショナルな製品ショットを作成するのに最適です。

・テンプレート

A high-resolution, studio-lit product photograph of a [product description]
on a [background surface/description]. The lighting is a [lighting setup,
e.g., three-point softbox setup] to [lighting purpose]. The camera angle is
a [angle type] to showcase [specific feature]. Ultra-realistic, with sharp
focus on [key detail]. [Aspect ratio].

【プロンプト例】

A high-resolution, studio-lit product photograph of a minimalist ceramic
coffee mug in matte black, presented on a polished concrete surface. The
lighting is a three-point softbox setup designed to create soft, diffused
highlights and eliminate harsh shadows. The camera angle is a slightly
elevated 45-degree shot to showcase its clean lines. Ultra-realistic, with
sharp focus on the steam rising from the coffee. Square image.

スタジオ照明による高解像度の製品写真。マットブラックのミニマルな陶器製コーヒーマグが、磨き上げられたコンクリートの表面に置かれている。照明は3点式ソフトボックスで、柔らかく拡散したハイライトを作り出し、強い影を消すように設計されている。カメラアングルは、マグのすっきりとしたラインを強調するため、やや上向きの45度から撮影されている。コーヒーから立ち上る湯気をシャープに捉え、非常にリアルな仕上がりとなっている。正方形の画像。

(5) ミニマリストとネガティブスペースデザイン
テキストを重ねる Web サイト、プレゼンテーション、マーケティング資料の背景を作成するのに最適です。

・テンプレート

A minimalist composition featuring a single [subject] positioned in the
[bottom-right/top-left/etc.] of the frame. The background is a vast, empty
[color] canvas, creating significant negative space. Soft, subtle lighting.
[Aspect ratio].

【プロンプト例】

A minimalist composition featuring a single, delicate red maple leaf
positioned in the bottom-right of the frame. The background is a vast, empty
off-white canvas, creating significant negative space for text. Soft,
diffused lighting from the top left. Square image.

フレームの右下に、繊細な赤いカエデの葉を一枚配置したミニマルな構図。背景は広大なオフホワイトのキャンバスで、テキストのための十分なネガティブスペースが確保されています。左上から柔らかく拡散した光を当て、正方形の画像を使用しています。

(6) シーケンシャルアート(漫画パネル/ストーリーボード)
キャラクターの一貫性とシーンの説明を基にして、視覚的にストーリーを伝えるパネルを作成します。

・テンプレート

A single comic book panel in a [art style] style. In the foreground,
[character description and action]. In the background, [setting details].
The panel has a [dialogue/caption box] with the text "[Text]". The lighting
creates a [mood] mood. [Aspect ratio].

【プロンプト例】

A single comic book panel in a gritty, noir art style with high-contrast
black and white inks. In the foreground, a detective in a trench coat stands
under a flickering streetlamp, rain soaking his shoulders. In the
background, the neon sign of a desolate bar reflects in a puddle. A caption
box at the top reads "The city was a tough place to keep secrets." The
lighting is harsh, creating a dramatic, somber mood. Landscape.

ざらざらとしたノワール調のアートスタイルで描かれた、コントラストの高い白黒インクのコミック1コマ。手前では、トレンチコートを着た刑事が、ちらつく街灯の下に立ち、肩を雨に濡らしている。背景には、寂れたバーのネオンサインが水たまりに映っている。上部のキャプションには「この街は秘密を守るのが難しい場所だった」と書かれている。強烈な照明が、ドラマチックで陰鬱な雰囲気を醸し出している。風景画。

6-2. 画像編集のプロンプト

これらの例は、編集、構成、およびスタイル転送のためにテキストプロンプトとともに画像を提供する方法を示しています。

(1) 要素の追加と削除
画像と変更内容をご提示ください。モデルは元の画像のスタイル、照明、遠近法に合わせて作成されます。

・テンプレート

Using the provided image of [subject], please [add/remove/modify] [element]
to/from the scene. Ensure the change is [description of how the change should
integrate].

【プロンプト例】

"Using the provided image of my cat, please add a small, knitted wizard hat
on its head. Make it look like it's sitting comfortably and matches the soft
lighting of the photo."

猫の画像をご用意いただき、小さなニットの魔法使い帽を頭にかぶせてください。猫が心地よく座っているように見え、写真の柔らかな光にマッチするようにしてください。

(2) インペインティング(セマンティックマスキング)
会話的に「マスク」を定義して、画像の特定の部分を編集し、残りの部分はそのまま残します。

・テンプレート

Using the provided image, change only the [specific element] to [new
element/description]. Keep everything else in the image exactly the same,
preserving the original style, lighting, and composition.

【プロンプト例】

"Using the provided image of a living room, change only the blue sofa to be
a vintage, brown leather chesterfield sofa. Keep the rest of the room,
including the pillows on the sofa and the lighting, unchanged."

提供されているリビングルームの画像を参考に、青いソファだけをヴィンテージの茶色のレザーチェスターフィールドソファに変更してください。ソファのクッションや照明など、部屋の残りの部分はそのままにしておいてください。

(3) スタイルの転送
画像を提供し、モデルにそのコンテンツを別の芸術的なスタイルで再現するよう依頼します。

・テンプレート

Transform the provided photograph of [subject] into the artistic style of [artist/art style]. Preserve the original composition but render it with [description of stylistic elements].

【プロンプト例】

"Transform the provided photograph of a modern city street at night into the artistic style of Vincent van Gogh's 'Starry Night'. Preserve the original composition of buildings and cars, but render all elements with swirling, impasto brushstrokes and a dramatic palette of deep blues and bright yellows."

提供された現代都市の夜景写真を、フィンセント・ファン・ゴッホの『星月夜』のような芸術的なスタイルに仕上げてください。建物や車の構図はそのままに、渦巻くような厚塗りの筆遣いと、深い青と鮮やかな黄色のドラマチックなパレットで、すべての要素を表現してください。

(4) 高度な合成:複数の画像を組み合わせる
複数の画像をコンテキストとして提供することで、新たな合成シーンを作成できます。製品のモックアップやクリエイティブなコラージュに最適です。

・テンプレート

Transform the provided photograph of [subject] into the artistic style of [artist/art style]. Preserve the oCreate a new image by combining the elements from the provided images. Take
the [element from image 1] and place it with/on the [element from image 2].
The final image should be a [description of the final scene].

【プロンプト例】

"Create a professional e-commerce fashion photo. Take the blue floral dress
from the first image and let the woman from the second image wear it.
Generate a realistic, full-body shot of the woman wearing the dress, with
the lighting and shadows adjusted to match the outdoor environment."

プロフェッショナルなeコマースファッション写真を作成しましょう。1枚目の写真の青い花柄のドレスを、2枚目の写真の女性に着せましょう。屋外の環境に合わせて光と影を調整し、ドレスを着た女性のリアルな全身ショットを作成します。

(5) 高忠実度のディテール保存
編集中に重要な詳細 (顔やロゴなど) が確実に保持されるようにするには、編集リクエストとともに詳細を記述してください。

・テンプレート

Using the provided images, place [element from image 2] onto [element from
image 1]. Ensure that the features of [element from image 1] remain
completely unchanged. The added element should [description of how the
element should integrate].

【プロンプト例】

"Take the first image of the woman with brown hair, blue eyes, and a neutral
expression. Add the logo from the second image onto her black t-shirt.
Ensure the woman's face and features remain completely unchanged. The logo
should look like it's naturally printed on the fabric, following the folds
of the shirt."

茶色の髪、青い目、そして無表情の女性の最初の画像を用意します。2枚目の画像のロゴを彼女の黒いTシャツに貼り付けます。女性の顔や特徴は全く変えないようにしてください。ロゴはシャツの折り目に沿って、生地に自然にプリントされているように見えるようにしてください。

6-3. ベストプラクティス

結果を「良い」から「素晴らしい」に高めるには、これらのプロフェッショナルな戦略をワークフローに取り入れましょう。

・非常に具体的に
詳細を記載すればするほど、より自由に表現できます。「ファンタジーの鎧」ではなく、「銀箔の模様が刻まれた、高い襟と鷹の翼のような形の肩甲を持つ、華やかなエルフのプレートアーマー」と説明しましょう。

・背景と意図を伝える
画像の目的を明確にしましょう。モデルが背景をどれだけ理解しているかが、最終的な成果物に影響を与えます。例えば、「高級でミニマルなスキンケアブランドのロゴを作成してください」という依頼は、「ロゴを作成してください」という依頼よりも、より良い結果が得られます。

・繰り返しと改良
最初から完璧な画像を期待しないでください。モデルの会話的な性質を利用して、小さな変更を加えましょう。「素晴らしいですね。でも、照明をもう少し温かみのある色にできますか?」や「すべてはそのままで、キャラクターの表情をもっと真面目なものに変えてください」など、フォローアップの提案をしましょう。

・ステップバイステップの指示を使う
多くの要素を含む複雑なシーンでは、指示をステップごとに分けましょう。「まず、夜明けの静かで霧深い森の背景を作成します。次に、前景に苔むした古代の石の祭壇を追加します。最後に、祭壇の上に光る剣を1本置きます。」

・意味的否定プロンプトを使用
「車がない」と言う代わりに、望ましいシーンを肯定的に説明します。「交通の兆候がない、空っぽで人気のない通り」

・カメラをコントロール
写真や映画で使われる表現を使って構図をコントロールします。
wide-angle shot、macro shot、low-angle perspective などの用語を使用

7. 制限事項

・最適な性能を得るには、次の言語を使用してください。
 EN、es-MX、ja-JP、zh-CN、hi-IN。

・画像生成では、オーディオまたはビデオ入力はサポートされていません。

・モデルは、ユーザーが明示的に要求した画像出力の数に常に正確に従うとは限りません。

・このモデルは、入力として最大3枚の画像を使用すると最適に機能します。

・画像のテキストを生成する場合、最初にテキストを生成し、次にテキストを含む画像を要求すると、Gemini は最も効果的に機能します。

・現在、EEA、CH、UK では子供の画像のアップロードはサポートされていません。

・生成されたすべての画像にはSynthID 透かしが含まれます。



いいなと思ったら応援しよう!