יצירת תמונות באמצעות Nano Banana
- לנסות אפליקציית Nano Banana 2
- או ליצור תרחיש משלכם באמצעות הנחיות:
-
נוצר על ידי Nano Banana 2 הנחיה: "תמונה של שער מבריק של מגזין, השער הכחול המינימליסטי כולל את המילים Nano Banana בגופן גדול ובולט. הטקסט מוצג בגופן עם תגים וממלא את התצוגה. בלי טקסט אחר. לפני הטקסט יש צילום של אדם בשמלה אלגנטית ומינימליסטית. היא מחזיקה בצורה שובבה את המספר 2, שהוא נקודת המיקוד.
ממקמים את מספר הגיליון ואת התאריך 'פברואר 2026' בפינה, יחד עם ברקוד. המגזין מונח על מדף בחנות מעצבים, על רקע קיר כתום עם טיח."יצירת תמונות מוצר מקצועיות ב-AI Studio -
נוצר על ידי Nano Banana Pro הנחיה: "תיצור סצנת קריקטורה תלת-ממדית, מיניאטורית, איזומטרית וברורה של לונדון, במבט על מזווית של 45 מעלות, עם ציוני הדרך המפורסמים ביותר והאלמנטים האדריכליים שלה. תשתמשו במרקמים רכים ומעודנים עם חומרים ריאליסטיים של PBR ותאורה וצללים עדינים שנראים כמו במציאות. שילוב של תנאי מזג האוויר הנוכחיים ישירות בסביבה העירונית כדי ליצור אווירה סוחפת. תשתמש בקומפוזיציה נקייה ומינימליסטית עם רקע רך בצבע אחיד. במרכז העליון, כותבים את הכותרת London (לונדון) בטקסט גדול ומודגש, מתחתיה מציבים סמל בולט של מזג האוויר, ואז את התאריך (בטקסט קטן) ואת הטמפרטורה (בטקסט בינוני). כל הטקסט צריך להיות מיושר למרכז עם ריווח עקבי, ויכול להיות שהוא יחפוף מעט את החלק העליון של הבניינים".מידע נוסף על ביסוס על חיפוש ועל ניסיון השימוש בו ב-AI Studio -
נוצר על ידי Nano Banana 2 הנחיה: "השתמשו בחיפוש תמונות כדי למצוא תמונות מדויקות של ציפור קצאל מפוארת. צור טפט יפהפה ביחס רוחב-גובה של 3:2 של הציפור הזו, עם מעבר צבע טבעי מלמעלה למטה וקומפוזיציה מינימלית".שימוש בהארקה של חיפוש תמונות ב-Google עם Nano Banana 2. רוצים לנסות את זה ב-AI Studio? -
נוצר על ידי Nano Banana Pro הנחיה: "תציב את הלוגו הזה במודעה יוקרתית לבושם בניחוח בננה. הלוגו משולב בצורה מושלמת בבקבוק".כדאי לנסות את השמירה של הפרטים ברמת דיוק גבוהה של Nano Banana ב-AI Studio -
נוצר על ידי Nano Banana Pro הנחיה: "תמונה של סצנה יומיומית בבית קפה הומה שמוגשת בו ארוחת בוקר. בחזית התמונה יש גבר אנימה עם שיער כחול, אחד מהאנשים הוא סקיצה בעיפרון, ואדם אחר הוא דמות בסטופ-מושן"אפשר להתנסות בסגנונות אמנותיים שונים עם Nano Banana ב-AI Studio -
נוצר על ידי Nano Banana Pro הנחיה: "תשתמש בחיפוש כדי לגלות איך התקבלה ההשקה של Gemini 3 Flash. תשתמש במידע הזה כדי לכתוב מאמר קצר בנושא (עם כותרות). תחזיר תמונה של המאמר כפי שהוא הופיע במגזין מבריק עם עיצוב מוקפד. זו תמונה של דף אחד מקופל, שמוצג בו מאמר על Gemini 3 Flash. תמונה ראשית אחת. כותרת בגופן סריפי." -
נוצר על ידי Nano Banana Pro הנחיה: "סמל שמייצג כלב חמוד. הררקע לבן. תיצור סמלים בסגנון תלת-ממדי צבעוני ומוחשי. אין טקסט".יצירת סמלים, סטיקרים ונכסים באמצעות Nano Banana ב-AI Studio -
נוצר על ידי Nano Banana 2 הנחיה: "צור תמונה איזומטרית מושלמת. זו לא תמונה ממוזערת, אלא תמונה שצולמה במקרה בצורה איזומטרית מושלמת. זו תמונה של גן מודרני יפהפה. יש בריכה גדולה בצורת הספרה 2 והמילים: Nano Banana 2."
Nano Banana הוא השם של יכולות יצירת התמונות המובנות ב-Gemini. Gemini יכול ליצור ולעבד תמונות בשיחה עם טקסט, תמונות או שילוב של שניהם. כך תוכלו ליצור ולערוך רכיבים חזותיים ולשפר אותם, עם שליטה חסרת תקדים.
Nano Banana הוא שם כולל לשלושה מודלים שונים שזמינים ב-Gemini API:
- Nano Banana 2: המודל Gemini 3.1 Flash Image Preview (
gemini-3.1-flash-image-preview). המודל הזה הוא המקבילה היעילה של Gemini 3 Pro Image, והוא עבר אופטימיזציה למהירות ולתרחישי שימוש של מפתחים שיוצרים תמונות בכמויות גדולות. - Nano Banana Pro: מודל Gemini 3 Pro Image Preview (
gemini-3-pro-image-preview). המודל הזה מיועד ליצירת נכסים מקצועיים, והוא משתמש בחשיבה רציונלית משופרת ("העמקה") כדי לפעול לפי הוראות מורכבות ולעבד טקסט ברמת דיוק גבוהה. - Nano Banana: מודל Gemini 2.5 Flash Image (
gemini-2.5-flash-image). המודל הזה מיועד למהירות וליעילות, ועבר אופטימיזציה למשימות עם נפח גבוה וזמן אחזור נמוך.
כל התמונות שנוצרות כוללות סימן מים של SynthID.
יצירת תמונות לפי טקסט
Python
from google import genai
from google.genai import types
from PIL import Image
client = genai.Client()
prompt = ("Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme")
response = client.models.generate_content(
model="gemini-3.1-flash-image-preview",
contents=[prompt],
)
for part in response.parts:
if part.text is not None:
print(part.text)
elif part.inline_data is not None:
image = part.as_image()
image.save("generated_image.png")
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
async function main() {
const ai = new GoogleGenAI({});
const prompt =
"Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme";
const response = await ai.models.generateContent({
model: "gemini-3.1-flash-image-preview",
contents: prompt,
});
for (const part of response.candidates[0].content.parts) {
if (part.text) {
console.log(part.text);
} else if (part.inlineData) {
const imageData = part.inlineData.data;
const buffer = Buffer.from(imageData, "base64");
fs.writeFileSync("gemini-native-image.png", buffer);
console.log("Image saved as gemini-native-image.png");
}
}
}
main();
Go
package main
import (
"context"
"fmt"
"log"
"os"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
result, _ := client.Models.GenerateContent(
ctx,
"gemini-3.1-flash-image-preview",
genai.Text("Create a picture of a nano banana dish in a " +
" fancy restaurant with a Gemini theme"),
)
for _, part := range result.Candidates[0].Content.Parts {
if part.Text != "" {
fmt.Println(part.Text)
} else if part.InlineData != nil {
imageBytes := part.InlineData.Data
outputFilename := "gemini_generated_image.png"
_ = os.WriteFile(outputFilename, imageBytes, 0644)
}
}
}
Java
import com.google.genai.Client;
import com.google.genai.types.GenerateContentConfig;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.Part;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class TextToImage {
public static void main(String[] args) throws IOException {
try (Client client = new Client()) {
GenerateContentConfig config = GenerateContentConfig.builder()
.responseModalities("TEXT", "IMAGE")
.build();
GenerateContentResponse response = client.models.generateContent(
"gemini-3.1-flash-image-preview",
"Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme",
config);
for (Part part : response.parts()) {
if (part.text().isPresent()) {
System.out.println(part.text().get());
} else if (part.inlineData().isPresent()) {
var blob = part.inlineData().get();
if (blob.data().isPresent()) {
Files.write(Paths.get("_01_generated_image.png"), blob.data().get());
}
}
}
}
}
}
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [
{"text": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"}
]
}]
}'
עריכת תמונות (טקסט ותמונה ליצירת תמונה)
תזכורת: לפני העלאת תמונה חשוב לוודא שיש לכם את הזכויות הנדרשות לשימוש בה. אסור ליצור תוכן שמפר את הזכויות של אנשים אחרים, כולל תמונות או סרטונים מטעים, מטרידים או פוגעים. השימוש שלך בשירות הזה של AI גנרטיבי כפוף למדיניות שלנו בנושא שימוש אסור.
מספקים תמונה ומשתמשים בהנחיות טקסט כדי להוסיף, להסיר או לשנות רכיבים, לשנות את הסגנון או להתאים את דירוג הצבעים.
בדוגמה הבאה מוצגת העלאה של תמונות מקודדות ב-base64.
למידע על כמה תמונות, מטען ייעודי גדול יותר וסוגי MIME נתמכים, אפשר לעיין בדף הבנת תמונות.
Python
from google import genai
from google.genai import types
from PIL import Image
client = genai.Client()
prompt = (
"Create a picture of my cat eating a nano-banana in a "
"fancy restaurant under the Gemini constellation",
)
image = Image.open("/path/to/cat_image.png")
response = client.models.generate_content(
model="gemini-3.1-flash-image-preview",
contents=[prompt, image],
)
for part in response.parts:
if part.text is not None:
print(part.text)
elif part.inline_data is not None:
image = part.as_image()
image.save("generated_image.png")
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
async function main() {
const ai = new GoogleGenAI({});
const imagePath = "path/to/cat_image.png";
const imageData = fs.readFileSync(imagePath);
const base64Image = imageData.toString("base64");
const prompt = [
{ text: "Create a picture of my cat eating a nano-banana in a" +
"fancy restaurant under the Gemini constellation" },
{
inlineData: {
mimeType: "image/png",
data: base64Image,
},
},
];
const response = await ai.models.generateContent({
model: "gemini-3.1-flash-image-preview",
contents: prompt,
});
for (const part of response.candidates[0].content.parts) {
if (part.text) {
console.log(part.text);
} else if (part.inlineData) {
const imageData = part.inlineData.data;
const buffer = Buffer.from(imageData, "base64");
fs.writeFileSync("gemini-native-image.png", buffer);
console.log("Image saved as gemini-native-image.png");
}
}
}
main();
Go
package main
import (
"context"
"fmt"
"log"
"os"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
imagePath := "/path/to/cat_image.png"
imgData, _ := os.ReadFile(imagePath)
parts := []*genai.Part{
genai.NewPartFromText("Create a picture of my cat eating a nano-banana in a fancy restaurant under the Gemini constellation"),
&genai.Part{
InlineData: &genai.Blob{
MIMEType: "image/png",
Data: imgData,
},
},
}
contents := []*genai.Content{
genai.NewContentFromParts(parts, genai.RoleUser),
}
result, _ := client.Models.GenerateContent(
ctx,
"gemini-3.1-flash-image-preview",
contents,
)
for _, part := range result.Candidates[0].Content.Parts {
if part.Text != "" {
fmt.Println(part.Text)
} else if part.InlineData != nil {
imageBytes := part.InlineData.Data
outputFilename := "gemini_generated_image.png"
_ = os.WriteFile(outputFilename, imageBytes, 0644)
}
}
}
Java
import com.google.genai.Client;
import com.google.genai.types.Content;
import com.google.genai.types.GenerateContentConfig;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.Part;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class TextAndImageToImage {
public static void main(String[] args) throws IOException {
try (Client client = new Client()) {
GenerateContentConfig config = GenerateContentConfig.builder()
.responseModalities("TEXT", "IMAGE")
.build();
GenerateContentResponse response = client.models.generateContent(
"gemini-3.1-flash-image-preview",
Content.fromParts(
Part.fromText("""
Create a picture of my cat eating a nano-banana in
a fancy restaurant under the Gemini constellation
"""),
Part.fromBytes(
Files.readAllBytes(
Path.of("src/main/resources/cat.jpg")),
"image/jpeg")),
config);
for (Part part : response.parts()) {
if (part.text().isPresent()) {
System.out.println(part.text().get());
} else if (part.inlineData().isPresent()) {
var blob = part.inlineData().get();
if (blob.data().isPresent()) {
Files.write(Paths.get("gemini_generated_image.png"), blob.data().get());
}
}
}
}
}
}
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d "{
\"contents\": [{
\"parts\":[
{\"text\": \"'Create a picture of my cat eating a nano-banana in a fancy restaurant under the Gemini constellation\"},
{
\"inline_data\": {
\"mime_type\":\"image/jpeg\",
\"data\": \"<BASE64_IMAGE_DATA>\"
}
}
]
}]
}"
עריכת תמונות בשיחה מרובת תפניות
להמשיך ליצור ולערוך תמונות בשיחה. הדרך המומלצת לשפר את התמונות היא באמצעות שיחה ב-Chat או שיחה מרובת תפניות. בדוגמה הבאה מוצגת הנחיה ליצירת אינפוגרפיקה בנושא פוטוסינתזה.
Python
from google import genai
from google.genai import types
client = genai.Client()
chat = client.chats.create(
model="gemini-3.1-flash-image-preview",
config=types.GenerateContentConfig(
response_modalities=['TEXT', 'IMAGE'],
tools=[{"google_search": {}}]
)
)
message = "Create a vibrant infographic that explains photosynthesis as if it were a recipe for a plant's favorite food. Show the \"ingredients\" (sunlight, water, CO2) and the \"finished dish\" (sugar/energy). The style should be like a page from a colorful kids' cookbook, suitable for a 4th grader."
response = chat.send_message(message)
for part in response.parts:
if part.text is not None:
print(part.text)
elif image:= part.as_image():
image.save("photosynthesis.png")
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const chat = ai.chats.create({
model: "gemini-3.1-flash-image-preview",
config: {
responseModalities: ['TEXT', 'IMAGE'],
tools: [{googleSearch: {}}],
},
});
}
await main();
const message = "Create a vibrant infographic that explains photosynthesis as if it were a recipe for a plant's favorite food. Show the \"ingredients\" (sunlight, water, CO2) and the \"finished dish\" (sugar/energy). The style should be like a page from a colorful kids' cookbook, suitable for a 4th grader."
let response = await chat.sendMessage({message});
for (const part of response.candidates[0].content.parts) {
if (part.text) {
console.log(part.text);
} else if (part.inlineData) {
const imageData = part.inlineData.data;
const buffer = Buffer.from(imageData, "base64");
fs.writeFileSync("photosynthesis.png", buffer);
console.log("Image saved as photosynthesis.png");
}
}
Go
package main
import (
"context"
"fmt"
"log"
"os"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
defer client.Close()
model := client.GenerativeModel("gemini-3.1-flash-image-preview")
model.GenerationConfig = &pb.GenerationConfig{
ResponseModalities: []pb.ResponseModality{genai.Text, genai.Image},
}
chat := model.StartChat()
message := "Create a vibrant infographic that explains photosynthesis as if it were a recipe for a plant's favorite food. Show the \"ingredients\" (sunlight, water, CO2) and the \"finished dish\" (sugar/energy). The style should be like a page from a colorful kids' cookbook, suitable for a 4th grader."
resp, err := chat.SendMessage(ctx, genai.Text(message))
if err != nil {
log.Fatal(err)
}
for _, part := range resp.Candidates[0].Content.Parts {
if txt, ok := part.(genai.Text); ok {
fmt.Printf("%s", string(txt))
} else if img, ok := part.(genai.ImageData); ok {
err := os.WriteFile("photosynthesis.png", img.Data, 0644)
if err != nil {
log.Fatal(err)
}
}
}
}
Java
import com.google.genai.Chat;
import com.google.genai.Client;
import com.google.genai.types.Content;
import com.google.genai.types.GenerateContentConfig;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.GoogleSearch;
import com.google.genai.types.ImageConfig;
import com.google.genai.types.Part;
import com.google.genai.types.RetrievalConfig;
import com.google.genai.types.Tool;
import com.google.genai.types.ToolConfig;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class MultiturnImageEditing {
public static void main(String[] args) throws IOException {
try (Client client = new Client()) {
GenerateContentConfig config = GenerateContentConfig.builder()
.responseModalities("TEXT", "IMAGE")
.tools(Tool.builder()
.googleSearch(GoogleSearch.builder().build())
.build())
.build();
Chat chat = client.chats.create("gemini-3.1-flash-image-preview", config);
GenerateContentResponse response = chat.sendMessage("""
Create a vibrant infographic that explains photosynthesis
as if it were a recipe for a plant's favorite food.
Show the "ingredients" (sunlight, water, CO2)
and the "finished dish" (sugar/energy).
The style should be like a page from a colorful
kids' cookbook, suitable for a 4th grader.
""");
for (Part part : response.parts()) {
if (part.text().isPresent()) {
System.out.println(part.text().get());
} else if (part.inlineData().isPresent()) {
var blob = part.inlineData().get();
if (blob.data().isPresent()) {
Files.write(Paths.get("photosynthesis.png"), blob.data().get());
}
}
}
// ...
}
}
}
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"role": "user",
"parts": [
{"text": "Create a vibrant infographic that explains photosynthesis as if it were a recipe for a plants favorite food. Show the \"ingredients\" (sunlight, water, CO2) and the \"finished dish\" (sugar/energy). The style should be like a page from a colorful kids cookbook, suitable for a 4th grader."}
]
}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"]
}
}'
אחר כך אפשר להשתמש באותו צ'אט כדי לשנות את השפה בגרפיקה לספרדית.
Python
message = "Update this infographic to be in Spanish. Do not change any other elements of the image."
aspect_ratio = "16:9" # "1:1","1:4","1:8","2:3","3:2","3:4","4:1","4:3","4:5","5:4","8:1","9:16","16:9","21:9"
resolution = "2K" # "512", "1K", "2K", "4K"
response = chat.send_message(message,
config=types.GenerateContentConfig(
response_format={"image": {aspect_ratio: aspect_ratio, image_size: resolution}},
))
for part in response.parts:
if part.text is not None:
print(part.text)
elif image:= part.as_image():
image.save("photosynthesis_spanish.png")
JavaScript
const message = 'Update this infographic to be in Spanish. Do not change any other elements of the image.';
const aspectRatio = '16:9';
const resolution = '2K';
let response = await chat.sendMessage({
message,
config: {
responseModalities: ['TEXT', 'IMAGE'],
responseFormat: {
image: {
aspectRatio: aspectRatio,
imageSize: resolution,
}
},
tools: [{googleSearch: {}}],
},
});
for (const part of response.candidates[0].content.parts) {
if (part.text) {
console.log(part.text);
} else if (part.inlineData) {
const imageData = part.inlineData.data;
const buffer = Buffer.from(imageData, "base64");
fs.writeFileSync("photosynthesis2.png", buffer);
console.log("Image saved as photosynthesis2.png");
}
}
Go
message = "Update this infographic to be in Spanish. Do not change any other elements of the image."
aspect_ratio = "16:9" // "1:1","1:4","1:8","2:3","3:2","3:4","4:1","4:3","4:5","5:4","8:1","9:16","16:9","21:9"
resolution = "2K" // "512", "1K", "2K", "4K"
model.GenerationConfig.ImageConfig = &pb.ImageConfig{
AspectRatio: aspect_ratio,
ImageSize: resolution,
}
resp, err = chat.SendMessage(ctx, genai.Text(message))
if err != nil {
log.Fatal(err)
}
for _, part := range resp.Candidates[0].Content.Parts {
if txt, ok := part.(genai.Text); ok {
fmt.Printf("%s", string(txt))
} else if img, ok := part.(genai.ImageData); ok {
err := os.WriteFile("photosynthesis_spanish.png", img.Data, 0644)
if err != nil {
log.Fatal(err)
}
}
}
Java
String aspectRatio = "16:9"; // "1:1","1:4","1:8","2:3","3:2","3:4","4:1","4:3","4:5","5:4","8:1","9:16","16:9","21:9"
String resolution = "2K"; // "512", "1K", "2K", "4K"
config = GenerateContentConfig.builder()
.responseModalities("TEXT", "IMAGE")
.imageConfig(ImageConfig.builder()
.aspectRatio(aspectRatio)
.imageSize(resolution)
.build())
.build();
response = chat.sendMessage(
"Update this infographic to be in Spanish. " +
"Do not change any other elements of the image.",
config);
for (Part part : response.parts()) {
if (part.text().isPresent()) {
System.out.println(part.text().get());
} else if (part.inlineData().isPresent()) {
var blob = part.inlineData().get();
if (blob.data().isPresent()) {
Files.write(Paths.get("photosynthesis_spanish.png"), blob.data().get());
}
}
}
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"contents": [
{
"role": "user",
"parts": [{"text": "Create a vibrant infographic that explains photosynthesis..."}]
},
{
"role": "model",
"parts": [{"inline_data": {"mime_type": "image/png", "data": "<PREVIOUS_IMAGE_DATA>"}}]
},
{
"role": "user",
"parts": [{"text": "Update this infographic to be in Spanish. Do not change any other elements of the image."}]
}
],
"tools": [{"google_search": {}}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"responseFormat": {
"image": {
"aspectRatio": "16:9",
"imageSize": "2K"
}
}
}
}'
חדש עם מודלים של Gemini 3 Image
Gemini 3 מציע מודלים חדשניים ליצירה ולעריכה של תמונות. Gemini 3.1 Flash Image מותאם למהירות ולתרחישי שימוש עם נפח גבוה, ו-Gemini 3 Pro Image מותאם ליצירת נכסים מקצועיים. הם נועדו להתמודד עם תהליכי העבודה המאתגרים ביותר באמצעות חשיבה רציונלית משופרת, והם מצטיינים במשימות מורכבות של יצירה ושינוי שכוללות כמה שלבים.
- פלט ברזולוציה גבוהה: יכולות מובנות ליצירת תמונות ברזולוציה של 1K, 2K ו-4K.
- Gemini 3.1 Flash Image מוסיף את הרזולוציה הקטנה יותר של 512 (0.5K).
- רינדור מתקדם של טקסט: אפשר ליצור טקסט קריא ומעוצב לאינפוגרפיקות, לתפריטים, לדיאגרמות ולנכסי שיווק.
- עיגון באמצעות חיפוש Google: המודל יכול להשתמש בחיפוש Google ככלי לאימות עובדות וליצירת תמונות על סמך נתונים בזמן אמת (למשל, מפות מזג אוויר עדכניות, תרשימי מניות, אירועים מהזמן האחרון).
- Gemini 3.1 Flash Image מוסיף את השילוב של עיגון באמצעות חיפוש Google לתמונות לצד חיפוש באינטרנט.
- מצב העמקה: המודל משתמש בתהליך של "חשיבה" כדי להסיק מסקנות מהנחיות מורכבות. הוא יוצר תמונות ביניים של מחשבות (שגלויות בקצה העורפי אבל לא מחויבות) כדי לשפר את הקומפוזיציה לפני שהוא יוצר את הפלט הסופי האיכותי.
- עד 14 תמונות לדוגמה: עכשיו אפשר לשלב עד 14 תמונות לדוגמה כדי ליצור את התמונה הסופית.
- יחסי גובה-רוחב חדשים: בגרסת טרום-ההשקה (Preview) של Gemini 3.1 Flash Image נוספו יחסי גובה-רוחב של 1:4, 4:1, 1:8 ו-8:1.
אפשר להשתמש בעד 14 תמונות לדוגמה
מודלים של תמונות ב-Gemini 3 מאפשרים לכם לערבב עד 14 תמונות לדוגמה. התמונות האלה יכולות לכלול:
| תצוגה מקדימה של תמונות ב-Gemini 3.1 Flash | תצוגה מקדימה של תמונות ב-Gemini 3 Pro |
|---|---|
| עד 10 תמונות של אובייקטים עם רמת דיוק גבוהה שייכללו בתמונה הסופית | עד 6 תמונות של אובייקטים ברמת דיוק גבוהה שייכללו בתמונה הסופית |
| עד 4 תמונות של דמויות כדי לשמור על עקביות הדמויות | עד 5 תמונות של דמויות כדי לשמור על עקביות הדמויות |
Python
from google import genai
from google.genai import types
from PIL import Image
prompt = "An office group photo of these people, they are making funny faces."
aspect_ratio = "5:4" # "1:1","1:4","1:8","2:3","3:2","3:4","4:1","4:3","4:5","5:4","8:1","9:16","16:9","21:9"
resolution = "2K" # "512", "1K", "2K", "4K"
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.1-flash-image-preview",
contents=[
prompt,
Image.open('person1.png'),
Image.open('person2.png'),
Image.open('person3.png'),
Image.open('person4.png'),
Image.open('person5.png'),
],
config=types.GenerateContentConfig(
response_modalities=['TEXT', 'IMAGE'],
response_format={"image": {aspect_ratio: aspect_ratio, image_size: resolution}},
)
)
for part in response.parts:
if part.text is not None:
print(part.text)
elif image:= part.as_image():
image.save("office.png")
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
async function main() {
const ai = new GoogleGenAI({});
const prompt =
'An office group photo of these people, they are making funny faces.';
const aspectRatio = '5:4';
const resolution = '2K';
const contents = [
{ text: prompt },
{
inlineData: {
mimeType: "image/jpeg",
data: base64ImageFile1,
},
},
{
inlineData: {
mimeType: "image/jpeg",
data: base64ImageFile2,
},
},
{
inlineData: {
mimeType: "image/jpeg",
data: base64ImageFile3,
},
},
{
inlineData: {
mimeType: "image/jpeg",
data: base64ImageFile4,
},
},
{
inlineData: {
mimeType: "image/jpeg",
data: base64ImageFile5,
},
}
];
const response = await ai.models.generateContent({
model: 'gemini-3.1-flash-image-preview',
contents: contents,
config: {
responseModalities: ['TEXT', 'IMAGE'],
responseFormat: {
image: {
aspectRatio: aspectRatio,
imageSize: resolution,
}
},
},
});
for (const part of response.candidates[0].content.parts) {
if (part.text) {
console.log(part.text);
} else if (part.inlineData) {
const imageData = part.inlineData.data;
const buffer = Buffer.from(imageData, "base64");
fs.writeFileSync("image.png", buffer);
console.log("Image saved as image.png");
}
}
}
main();
Go
package main
import (
"context"
"fmt"
"log"
"os"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
defer client.Close()
model := client.GenerativeModel("gemini-3.1-flash-image-preview")
model.GenerationConfig = &pb.GenerationConfig{
ResponseModalities: []pb.ResponseModality{genai.Text, genai.Image},
ImageConfig: &pb.ImageConfig{
AspectRatio: "5:4",
ImageSize: "2K",
},
}
img1, err := os.ReadFile("person1.png")
if err != nil { log.Fatal(err) }
img2, err := os.ReadFile("person2.png")
if err != nil { log.Fatal(err) }
img3, err := os.ReadFile("person3.png")
if err != nil { log.Fatal(err) }
img4, err := os.ReadFile("person4.png")
if err != nil { log.Fatal(err) }
img5, err := os.ReadFile("person5.png")
if err != nil { log.Fatal(err) }
parts := []genai.Part{
genai.Text("An office group photo of these people, they are making funny faces."),
genai.ImageData{MIMEType: "image/png", Data: img1},
genai.ImageData{MIMEType: "image/png", Data: img2},
genai.ImageData{MIMEType: "image/png", Data: img3},
genai.ImageData{MIMEType: "image/png", Data: img4},
genai.ImageData{MIMEType: "image/png", Data: img5},
}
resp, err := model.GenerateContent(ctx, parts...)
if err != nil {
log.Fatal(err)
}
for _, part := range resp.Candidates[0].Content.Parts {
if txt, ok := part.(genai.Text); ok {
fmt.Printf("%s", string(txt))
} else if img, ok := part.(genai.ImageData); ok {
err := os.WriteFile("office.png", img.Data, 0644)
if err != nil {
log.Fatal(err)
}
}
}
}
Java
import com.google.genai.Client;
import com.google.genai.types.Content;
import com.google.genai.types.GenerateContentConfig;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.ImageConfig;
import com.google.genai.types.Part;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class GroupPhoto {
public static void main(String[] args) throws IOException {
try (Client client = new Client()) {
GenerateContentConfig config = GenerateContentConfig.builder()
.responseModalities("TEXT", "IMAGE")
.imageConfig(ImageConfig.builder()
.aspectRatio("5:4")
.imageSize("2K")
.build())
.build();
GenerateContentResponse response = client.models.generateContent(
"gemini-3.1-flash-image-preview",
Content.fromParts(
Part.fromText("An office group photo of these people, they are making funny faces."),
Part.fromBytes(Files.readAllBytes(Path.of("person1.png")), "image/png"),
Part.fromBytes(Files.readAllBytes(Path.of("person2.png")), "image/png"),
Part.fromBytes(Files.readAllBytes(Path.of("person3.png")), "image/png"),
Part.fromBytes(Files.readAllBytes(Path.of("person4.png")), "image/png"),
Part.fromBytes(Files.readAllBytes(Path.of("person5.png")), "image/png")
), config);
for (Part part : response.parts()) {
if (part.text().isPresent()) {
System.out.println(part.text().get());
} else if (part.inlineData().isPresent()) {
var blob = part.inlineData().get();
if (blob.data().isPresent()) {
Files.write(Paths.get("office.png"), blob.data().get());
}
}
}
}
}
}
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d "{
\"contents\": [{
\"parts\":[
{\"text\": \"An office group photo of these people, they are making funny faces.\"},
{\"inline_data\": {\"mime_type\":\"image/png\", \"data\": \"<BASE64_DATA_IMG_1>\"}},
{\"inline_data\": {\"mime_type\":\"image/png\", \"data\": \"<BASE64_DATA_IMG_2>\"}},
{\"inline_data\": {\"mime_type\":\"image/png\", \"data\": \"<BASE64_DATA_IMG_3>\"}},
{\"inline_data\": {\"mime_type\":\"image/png\", \"data\": \"<BASE64_DATA_IMG_4>\"}},
{\"inline_data\": {\"mime_type\":\"image/png\", \"data\": \"<BASE64_DATA_IMG_5>\"}}
]
}],
\"generationConfig\": {
\"responseModalities\": [\"TEXT\", \"IMAGE\"],
\"responseFormat\": {
\"image\": {
\"aspectRatio\": \"5:4\",
\"imageSize\": \"2K\"
}
}
}
}"
עיגון באמצעות חיפוש Google
אתם יכולים להשתמש בכלי חיפוש Google כדי ליצור תמונות על סמך מידע בזמן אמת, כמו תחזיות מזג אוויר, תרשימי מניות או אירועים מהזמן האחרון.
שימו לב: כשמשתמשים ב-עיגון באמצעות חיפוש Google ליצירת תמונות, תוצאות החיפוש שמבוססות על תמונות לא מועברות למודל הגנרטיבי ולא נכללות בתשובה (ראו עיגון באמצעות חיפוש Google לתמונות).
Python
from google import genai
prompt = "Visualize the current weather forecast for the next 5 days in San Francisco as a clean, modern weather chart. Add a visual on what I should wear each day"
aspect_ratio = "16:9" # "1:1","1:4","1:8","2:3","3:2","3:4","4:1","4:3","4:5","5:4","8:1","9:16","16:9","21:9"
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.1-flash-image-preview",
contents=prompt,
config=types.GenerateContentConfig(
response_modalities=['Text', 'Image'],
response_format={"image": {aspect_ratio: aspect_ratio,}},
tools=[{"google_search": {}}]
)
)
for part in response.parts:
if part.text is not None:
print(part.text)
elif image:= part.as_image():
image.save("weather.png")
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
async function main() {
const ai = new GoogleGenAI({});
const prompt = 'Visualize the current weather forecast for the next 5 days in San Francisco as a clean, modern weather chart. Add a visual on what I should wear each day';
const aspectRatio = '16:9';
const resolution = '2K';
const response = await ai.models.generateContent({
model: 'gemini-3.1-flash-image-preview',
contents: prompt,
config: {
responseModalities: ['TEXT', 'IMAGE'],
responseFormat: {
image: {
aspectRatio: aspectRatio,
imageSize: resolution,
}
},
tools: [{ googleSearch: {} }]
},
});
for (const part of response.candidates[0].content.parts) {
if (part.text) {
console.log(part.text);
} else if (part.inlineData) {
const imageData = part.inlineData.data;
const buffer = Buffer.from(imageData, "base64");
fs.writeFileSync("image.png", buffer);
console.log("Image saved as image.png");
}
}
}
main();
Java
import com.google.genai.Client;
import com.google.genai.types.GenerateContentConfig;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.GoogleSearch;
import com.google.genai.types.ImageConfig;
import com.google.genai.types.Part;
import com.google.genai.types.Tool;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class SearchGrounding {
public static void main(String[] args) throws IOException {
try (Client client = new Client()) {
GenerateContentConfig config = GenerateContentConfig.builder()
.responseModalities("TEXT", "IMAGE")
.imageConfig(ImageConfig.builder()
.aspectRatio("16:9")
.build())
.tools(Tool.builder()
.googleSearch(GoogleSearch.builder().build())
.build())
.build();
GenerateContentResponse response = client.models.generateContent(
"gemini-3.1-flash-image-preview", """
Visualize the current weather forecast for the next 5 days
in San Francisco as a clean, modern weather chart.
Add a visual on what I should wear each day
""",
config);
for (Part part : response.parts()) {
if (part.text().isPresent()) {
System.out.println(part.text().get());
} else if (part.inlineData().isPresent()) {
var blob = part.inlineData().get();
if (blob.data().isPresent()) {
Files.write(Paths.get("weather.png"), blob.data().get());
}
}
}
}
}
}
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{"parts": [{"text": "Visualize the current weather forecast for the next 5 days in San Francisco as a clean, modern weather chart. Add a visual on what I should wear each day"}]}],
"tools": [{"google_search": {}}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"responseFormat": {
"image": {"aspectRatio": "16:9"}
}
}
}'
התשובה כוללת את groundingMetadata שמכיל את השדות הנדרשים הבאים:
-
searchEntryPoint: מכיל את ה-HTML וה-CSS לעיבוד הצעות החיפוש הנדרשות. -
groundingChunks: מחזירה את 3 המקורות המובילים באינטרנט ששימשו להארקה של התמונה שנוצרה
עיגון באמצעות חיפוש Google לתמונות (3.1 Flash)
עיגון באמצעות חיפוש Google לתמונות מאפשר למודלים להשתמש בתמונות מהאינטרנט שאוחזרו באמצעות חיפוש Google כהקשר חזותי ליצירת תמונות. חיפוש תמונות הוא סוג חיפוש חדש בכלי הקיים 'עיגון באמצעות חיפוש Google', והוא פועל לצד חיפוש רגיל באינטרנט.
כדי להפעיל את חיפוש התמונות, צריך להגדיר את הכלי googleSearch בבקשת ה-API ולציין את imageSearch באובייקט searchTypes. אפשר להשתמש בחיפוש תמונות בנפרד או יחד עם חיפוש באינטרנט.
הערה: אי אפשר להשתמש בעיגון באמצעות חיפוש Google כדי לחפש אנשים.
Python
from google import genai
prompt = "A detailed painting of a Timareta butterfly resting on a flower"
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.1-flash-image-preview",
contents=prompt,
config=types.GenerateContentConfig(
response_modalities=["IMAGE"],
tools=[
types.Tool(google_search=types.GoogleSearch(
search_types=types.SearchTypes(
web_search=types.WebSearch(),
image_search=types.ImageSearch()
)
))
]
)
)
# Display grounding sources if available
if response.candidates and response.candidates[0].grounding_metadata and response.candidates[0].grounding_metadata.search_entry_point:
display(HTML(response.candidates[0].grounding_metadata.search_entry_point.rendered_content))
JavaScript
import { GoogleGenAI } from "@google/genai";
async function main() {
const ai = new GoogleGenAI({});
const prompt = "A detailed painting of a Timareta butterfly resting on a flower";
const response = await ai.models.generateContent({
model: "gemini-3.1-flash-image-preview",
contents: prompt,
config: {
responseModalities: ["IMAGE"],
tools: [
{
googleSearch: {
searchTypes: {
webSearch: {},
imageSearch: {}
}
}
}
]
}
});
// Display grounding sources if available
if (response.candidates && response.candidates[0].groundingMetadata && response.candidates[0].groundingMetadata.searchEntryPoint) {
console.log(response.candidates[0].groundingMetadata.searchEntryPoint.renderedContent);
}
}
main();
Go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
pb "google.golang.org/genai/schema"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
defer client.Close()
model := client.GenerativeModel("gemini-3.1-flash-image-preview")
model.Tools = []*pb.Tool{
{
GoogleSearch: &pb.GoogleSearch{
SearchTypes: &pb.SearchTypes{
WebSearch: &pb.WebSearch{},
ImageSearch: &pb.ImageSearch{},
},
},
},
}
model.GenerationConfig = &pb.GenerationConfig{
ResponseModalities: []pb.ResponseModality{genai.Image},
}
prompt := "A detailed painting of a Timareta butterfly resting on a flower"
resp, err := model.GenerateContent(ctx, genai.Text(prompt))
if err != nil {
log.Fatal(err)
}
if resp.Candidates[0].GroundingMetadata != nil && resp.Candidates[0].GroundingMetadata.SearchEntryPoint != nil {
fmt.Println(resp.Candidates[0].GroundingMetadata.SearchEntryPoint.RenderedContent)
}
}
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{"parts": [{"text": "A detailed painting of a Timareta butterfly resting on a flower"}]}],
"tools": [{"google_search": {"searchTypes": {"webSearch": {}, "imageSearch": {}}}}],
"generationConfig": {
"responseModalities": ["IMAGE"]
}
}'
דרישות להצגה
כשמשתמשים בחיפוש תמונות במסגרת עיגון באמצעות חיפוש Google, צריך לפעול בהתאם לתנאים הבאים:
- ציון המקור: אתם צריכים לספק קישור לדף האינטרנט שבו נמצאת תמונת המקור ('הדף המכיל', לא קובץ התמונה עצמו) באופן שהמשתמש יזהה כקישור.
- ניווט ישיר: אם בחרתם גם להציג את תמונות המקור, אתם צריכים לספק נתיב ישיר בלחיצה אחת מתמונות המקור לדף האינטרנט המכיל את המקור. אסור להשתמש בהטמעה אחרת שמעכבת או מסתירה את הגישה של משתמש הקצה לדף האינטרנט המקורי, כולל, בין היתר, שימוש בנתיב מרובה קליקים או בצופה תמונות ביניים.
תשובה
בתשובות מבוססות-קרקע שמתקבלות באמצעות חיפוש תמונות, ה-API מספק שיוך ברור ומטא-נתונים כדי לקשר את הפלט שלו למקורות מאומתים. השדות העיקריים באובייקט groundingMetadata כוללים:
-
imageSearchQueries: השאילתות הספציפיות שבהן המודל משתמש כדי להבין את ההקשר החזותי (חיפוש תמונות).
groundingChunks: מכיל מידע על המקור של התוצאות שאוחזרו. במקורות תמונות, כתובות ה-URL האלה יוחזרו ככתובות URL להפניה אוטומטית באמצעות סוג חדש של נתח תמונה. החלק הזה כולל:-
uri: כתובת ה-URL של דף האינטרנט לצורך שיוך (דף הנחיתה). -
image_uri: כתובת ה-URL הישירה של התמונה.
-
groundingSupports: מספק מיפויים ספציפיים שמקשרים את התוכן שנוצר למקור הציטוט הרלוונטי שלו בקטעים.
searchEntryPoint: כולל את הצ'יפ Google Search (חיפוש Google) שמכיל HTML ו-CSS תואמים לעיבוד של הצעות לחיפוש.
יצירת תמונות ברזולוציה של עד 4K
מודלים של Gemini 3 ליצירת תמונות יוצרים כברירת מחדל תמונות באיכות 1K, אבל יכולים גם ליצור תמונות באיכות 2K, 4K ו-512 (0.5K) (רק ב-Gemini 3.1 Flash Image). כדי ליצור נכסים ברזולוציה גבוהה יותר, מציינים את image_size ב-generation_config.
חובה להשתמש באות K גדולה (לדוגמה: 1K, 2K, 4K). הערך של 512 לא מסתיים בסיומת 'K'. פרמטרים באותיות קטנות (למשל, 1k) יידחו.
Python
from google import genai
from google.genai import types
prompt = "Da Vinci style anatomical sketch of a dissected Monarch butterfly. Detailed drawings of the head, wings, and legs on textured parchment with notes in English."
aspect_ratio = "1:1" # "1:1","1:4","1:8","2:3","3:2","3:4","4:1","4:3","4:5","5:4","8:1","9:16","16:9","21:9"
resolution = "1K" # "512", "1K", "2K", "4K"
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.1-flash-image-preview",
contents=prompt,
config=types.GenerateContentConfig(
response_modalities=['TEXT', 'IMAGE'],
response_format={"image": {aspect_ratio: aspect_ratio, image_size: resolution}},
)
)
for part in response.parts:
if part.text is not None:
print(part.text)
elif image:= part.as_image():
image.save("butterfly.png")
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
async function main() {
const ai = new GoogleGenAI({});
const prompt =
'Da Vinci style anatomical sketch of a dissected Monarch butterfly. Detailed drawings of the head, wings, and legs on textured parchment with notes in English.';
const aspectRatio = '1:1';
const resolution = '1K';
const response = await ai.models.generateContent({
model: 'gemini-3.1-flash-image-preview',
contents: prompt,
config: {
responseModalities: ['TEXT', 'IMAGE'],
responseFormat: {
image: {
aspectRatio: aspectRatio,
imageSize: resolution,
}
},
},
});
for (const part of response.candidates[0].content.parts) {
if (part.text) {
console.log(part.text);
} else if (part.inlineData) {
const imageData = part.inlineData.data;
const buffer = Buffer.from(imageData, "base64");
fs.writeFileSync("image.png", buffer);
console.log("Image saved as image.png");
}
}
}
main();
Go
package main
import (
"context"
"fmt"
"log"
"os"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
defer client.Close()
model := client.GenerativeModel("gemini-3.1-flash-image-preview")
model.GenerationConfig = &pb.GenerationConfig{
ResponseModalities: []pb.ResponseModality{genai.Text, genai.Image},
ImageConfig: &pb.ImageConfig{
AspectRatio: "1:1",
ImageSize: "1K",
},
}
prompt := "Da Vinci style anatomical sketch of a dissected Monarch butterfly. Detailed drawings of the head, wings, and legs on textured parchment with notes in English."
resp, err := model.GenerateContent(ctx, genai.Text(prompt))
if err != nil {
log.Fatal(err)
}
for _, part := range resp.Candidates[0].Content.Parts {
if txt, ok := part.(genai.Text); ok {
fmt.Printf("%s", string(txt))
} else if img, ok := part.(genai.ImageData); ok {
err := os.WriteFile("butterfly.png", img.Data, 0644)
if err != nil {
log.Fatal(err)
}
}
}
}
Java
import com.google.genai.Client;
import com.google.genai.types.GenerateContentConfig;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.GoogleSearch;
import com.google.genai.types.ImageConfig;
import com.google.genai.types.Part;
import com.google.genai.types.Tool;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class HiRes {
public static void main(String[] args) throws IOException {
try (Client client = new Client()) {
GenerateContentConfig config = GenerateContentConfig.builder()
.responseModalities("TEXT", "IMAGE")
.imageConfig(ImageConfig.builder()
.aspectRatio("16:9")
.imageSize("4K")
.build())
.build();
GenerateContentResponse response = client.models.generateContent(
"gemini-3.1-flash-image-preview", """
Da Vinci style anatomical sketch of a dissected Monarch butterfly.
Detailed drawings of the head, wings, and legs on textured
parchment with notes in English.
""",
config);
for (Part part : response.parts()) {
if (part.text().isPresent()) {
System.out.println(part.text().get());
} else if (part.inlineData().isPresent()) {
var blob = part.inlineData().get();
if (blob.data().isPresent()) {
Files.write(Paths.get("butterfly.png"), blob.data().get());
}
}
}
}
}
}
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{"parts": [{"text": "Da Vinci style anatomical sketch of a dissected Monarch butterfly. Detailed drawings of the head, wings, and legs on textured parchment with notes in English."}]}],
"tools": [{"google_search": {}}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"responseFormat": {
"image": {"aspectRatio": "1:1", "imageSize": "1K"}
}
}
}'
זוהי תמונה לדוגמה שנוצרה מההנחיה הזו:
תהליך החשיבה
מודלים של Gemini 3 ליצירת תמונות הם מודלים חושבים שמשתמשים בתהליך חשיבה רציונלית ("Thinking") כדי לענות על הנחיות מורכבות. התכונה הזו מופעלת כברירת מחדל ואי אפשר להשבית אותה ב-API. כדי לקבל מידע נוסף על תהליך החשיבה, אפשר לעיין במדריך תהליך החשיבה של Gemini.
המודל יוצר עד שתי תמונות ביניים כדי לבדוק את הקומפוזיציה והלוגיקה. התמונה האחרונה שמוצגת בשלב החשיבה היא גם התמונה הסופית.
אתם יכולים לבדוק את המחשבות שהובילו ליצירת התמונה הסופית.
Python
for part in response.parts:
if part.thought:
if part.text:
print(part.text)
elif image:= part.as_image():
image.show()
JavaScript
for (const part of response.candidates[0].content.parts) {
if (part.thought) {
if (part.text) {
console.log(part.text);
} else if (part.inlineData) {
const imageData = part.inlineData.data;
const buffer = Buffer.from(imageData, 'base64');
fs.writeFileSync('image.png', buffer);
console.log('Image saved as image.png');
}
}
}
שליטה ברמות החשיבה
עם Gemini 3.1 Flash Image, אתם יכולים לשלוט בכמות החשיבה שהמודל משתמש בה כדי לאזן בין איכות לבין זמן האחזור. ערך ברירת המחדל thinkingLevel הוא minimal, והרמות הנתמכות הן minimal ו-high. הגדרת thinkingLevel ל-minimal מספקת תשובות עם זמן האחזור הנמוך ביותר. חשוב לציין ש'חשיבה מינימלית' לא אומרת שהמודל לא משתמש בחשיבה בכלל.
אפשר להוסיף את הערך הבוליאני includeThoughts כדי לקבוע אם המחשבות שנוצרו על ידי המודל יוחזרו בתשובה או יישארו מוסתרות.
Python
from google import genai
response = client.models.generate_content(
model="gemini-3.1-flash-image-preview",
contents="A futuristic city built inside a giant glass bottle floating in space",
config=types.GenerateContentConfig(
response_modalities=["IMAGE"],
thinking_config=types.ThinkingConfig(
thinking_level="High",
include_thoughts=True
),
)
)
for part in response.parts:
if part.thought: # Skip outputting thoughts
continue
if part.text:
display(Markdown(part.text))
elif image:= part.as_image():
image.show()
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
async function main() {
const ai = new GoogleGenAI({});
const response = await ai.models.generateContent({
model: "gemini-3.1-flash-image-preview",
contents: "A futuristic city built inside a giant glass bottle floating in space",
config: {
responseModalities: ["IMAGE"],
thinkingConfig: {
thinkingLevel: "High",
includeThoughts: true
},
},
});
for (const part of response.candidates[0].content.parts) {
if (part.thought) { // Skip outputting thoughts
continue;
}
if (part.text) {
console.log(part.text);
} else if (part.inlineData) {
const imageData = part.inlineData.data;
const buffer = Buffer.from(imageData, "base64");
fs.writeFileSync("image.png", buffer);
console.log("Image saved as image.png");
}
}
}
main();
Go
package main
import (
"context"
"fmt"
"log"
"os"
"google.golang.org/genai"
pb "google.golang.org/genai/schema"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
defer client.Close()
model := client.GenerativeModel("gemini-3.1-flash-image-preview")
model.GenerationConfig = &pb.GenerationConfig{
ResponseModalities: []pb.ResponseModality{genai.Image},
ThinkingConfig: &pb.ThinkingConfig{
ThinkingLevel: "High",
IncludeThoughts: true,
},
}
prompt := "A futuristic city built inside a giant glass bottle floating in space"
resp, err := model.GenerateContent(ctx, genai.Text(prompt))
if err != nil {
log.Fatal(err)
}
for _, part := range resp.Candidates[0].Content.Parts {
if part.Thought { // Skip outputting thoughts
continue
}
if txt, ok := part.(genai.Text); ok {
fmt.Printf("%s", string(txt))
} else if img, ok := part.(genai.ImageData); ok {
err := os.WriteFile("image.png", img.Data, 0644)
if err != nil {
log.Fatal(err)
}
}
}
}
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{"parts": [{"text": "A futuristic city built inside a giant glass bottle floating in space"}]}],
"generationConfig": {
"responseModalities": ["IMAGE"],
"thinkingConfig": {
"thinkingLevel": "High",
"includeThoughts": true
}
}
}'
חשוב לזכור שהחיוב על אסימוני חשיבה מתבצע גם אם הערך של includeThoughts הוא true או false, כי תהליך החשיבה תמיד מתבצע כברירת מחדל, גם אם אתם צופים בתהליך וגם אם לא.
חתימות של מחשבות
חתימות מחשבה הן ייצוגים מוצפנים של תהליך החשיבה הפנימי של המודל, והן משמשות לשמירה על הקשר של הנימוקים באינטראקציות מרובות. כל התשובות כוללות את השדה thought_signature. ככלל, אם אתם מקבלים חתימת מחשבה בתשובה של מודל, אתם צריכים להעביר אותה בדיוק כמו שהיא התקבלה כשאתם שולחים את היסטוריית השיחות בתור הבא. אם לא תפיצו את חתימות המחשבות, יכול להיות שהתשובה תיכשל. במאמר בנושא חתימת מחשבה יש הסברים נוספים על חתימות באופן כללי.
כך פועלות חתימות מחשבה:
- לכל
inline_dataהחלקים עם התמונהmimetypeשכלולים בתשובה צריכה להיות חתימה. - אם יש חלקי טקסט בתחילת התשובה (לפני התמונה הראשונה) מיד אחרי המחשבות, גם לחלק הטקסט הראשון צריך להיות חתימה.
- אם
inline_dataחלקים עם תמונהmimetypeהם חלק ממחשבות, לא יהיו להם חתימות.
בדוגמה הבאה אפשר לראות איפה נכללים חתימות המחשבה:
[
{
"inline_data": {
"data": "<base64_image_data_0>",
"mime_type": "image/png"
},
"thought": true // Thoughts don't have signatures
},
{
"inline_data": {
"data": "<base64_image_data_1>",
"mime_type": "image/png"
},
"thought": true // Thoughts don't have signatures
},
{
"inline_data": {
"data": "<base64_image_data_2>",
"mime_type": "image/png"
},
"thought": true // Thoughts don't have signatures
},
{
"text": "Here is a step-by-step guide to baking macarons, presented in three separate images.\n\n### Step 1: Piping the Batter\n\nThe first step after making your macaron batter is to pipe it onto a baking sheet. This requires a steady hand to create uniform circles.\n\n",
"thought_signature": "<Signature_A>" // The first non-thought part always has a signature
},
{
"inline_data": {
"data": "<base64_image_data_3>",
"mime_type": "image/png"
},
"thought_signature": "<Signature_B>" // All image parts have a signatures
},
{
"text": "\n\n### Step 2: Baking and Developing Feet\n\nOnce piped, the macarons are baked in the oven. A key sign of a successful bake is the development of \"feet\"—the ruffled edge at the base of each macaron shell.\n\n"
// Follow-up text parts don't have signatures
},
{
"inline_data": {
"data": "<base64_image_data_4>",
"mime_type": "image/png"
},
"thought_signature": "<Signature_C>" // All image parts have a signatures
},
{
"text": "\n\n### Step 3: Assembling the Macaron\n\nThe final step is to pair the cooled macaron shells by size and sandwich them together with your desired filling, creating the classic macaron dessert.\n\n"
},
{
"inline_data": {
"data": "<base64_image_data_5>",
"mime_type": "image/png"
},
"thought_signature": "<Signature_D>" // All image parts have a signatures
}
]
מצבים אחרים ליצירת תמונות
Gemini תומך במצבי אינטראקציה אחרים עם תמונות על סמך מבנה ההנחיה וההקשר, כולל:
- טקסט לתמונה(או לתמונות) וטקסט (משולב): יצירת תמונות עם טקסט שקשור אליהן.
- הנחיה לדוגמה: "צור מתכון מאויר לפאייה".
- תמונה/תמונות וטקסט לתמונה/תמונות וטקסט (משולבים): משתמש בתמונות ובטקסט שמוזנים כדי ליצור תמונות וטקסט חדשים שקשורים אליהם.
- הנחיה לדוגמה: (עם תמונה של חדר מרוהט) "אילו ספות בצבעים אחרים יתאימו לחלל שלי? אפשר לעדכן את התמונה?"
יצירה של קבוצת תמונות
אם אתם צריכים ליצור הרבה תמונות, אתם יכולים להשתמש ב-Batch API. בתמורה לזמן תגובה של עד 24 שעות, תקבלו מגבלות קצב גבוהות יותר.
כדאי לעיין בתיעוד של Batch API image generation ובמדריך לדוגמאות ולקוד של Batch API image.
מדריך ואסטרטגיות ליצירת הנחיות
כדי ליצור תמונות בצורה טובה, צריך להבין עיקרון בסיסי אחד:
צריך לתאר את הסצנה, לא רק לכלול רשימה של מילות מפתח. החוזקה העיקרית של המודל היא ההבנה העמוקה שלו של השפה. פסקה נרטיבית ותיאורית כמעט תמיד תניב תמונה טובה ועקבית יותר מרשימה של מילים לא קשורות.
הנחיות ליצירת תמונות
השיטות הבאות יעזרו לכם ליצור הנחיות יעילות כדי ליצור בדיוק את התמונות שאתם מחפשים.
צילום
כדי ליצור תמונות ריאליסטיות, כדאי להשתמש במונחים מעולם הצילום. כדי להנחות את המודל ליצור תוצאה ריאליסטית, כדאי לציין זוויות צילום, סוגי עדשות, תאורה ופרטים קטנים.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
| תמונה של פורטרט בתקריב של אמן קרמיקה יפני מבוגר עם קמטים עמוקים שנוצרו מחשיפה לשמש וחיוך חם ומבין. הוא בודק בקפידה קערת תה חדשה עם זיגוג. הסביבה היא סדנה כפרית שטופת שמש. הסצנה מוארת באור רך של שעת הזהב שנכנס דרך חלון ומדגיש את הטקסטורה העדינה של החמר. צולם בעדשת פורטרט של 85 מ"מ, ולכן הרקע רך ומטושטש (אפקט בוקה). האווירה הכללית היא שלווה ומקצועית. כיוון לאורך. |
|
איורים וסטיקרים מעוצבים
כדי ליצור סטיקרים, סמלים או נכסים, צריך לציין במפורש את הסגנון ולבקש רקע לבן.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
| סטיקר בסגנון קוואי של פנדה אדומה שמחה עם כובע קטן מבמבוק. הוא לועס עלה במבוק ירוק. העיצוב כולל קווי מתאר בולטים ונקיים, הצללה פשוטה בסגנון אנימציה ופלטת צבעים עשירה. הר רקע חייב להיות לבן. |
|
טקסט מדויק בתמונות
Gemini מצטיין ברינדור טקסט. חשוב לתת הנחיות ברורות לגבי הטקסט, סגנון הגופן (תיאורית) והעיצוב הכללי. שימוש בתצוגה מקדימה של תמונות ב-Gemini 3 Pro ליצירת נכסים מקצועיים.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
| צור לוגו מודרני ומינימליסטי לבית קפה בשם The Daily Grind. הטקסט צריך להיות בגופן sans-serif נקי ומודגש. ערכת הצבעים היא שחור ולבן. מציבים את הלוגו בעיגול. להשתמש בפולי קפה בצורה חכמה. |
|
מודלים של מוצרים וצילום מסחרי
מושלם ליצירת צילומי מוצר נקיים ומקצועיים למסחר אלקטרוני, לפרסום או למיתוג.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
| צילום מוצר ברזולוציה גבוהה עם תאורת סטודיו של ספל קפה מקרמיקה שחורה מט, שמוצג על משטח בטון מלוטש. התאורה היא מערך של שלושה סופטבוקסים שנועד ליצור אזורים בהירים רכים ומפוזרים ולמנוע צללים חדים. זווית המצלמה היא צילום בזווית של 45 מעלות, קצת מלמעלה, כדי להציג את הקווים הנקיים של המכשיר. תמונה אולטרה-ריאליסטית עם פוקוס חד על האדים שעולים מהקפה. תמונה מרובעת. |
|
עיצוב מינימליסטי עם שטח ריק
אפשר להשתמש בהן כדי ליצור רקעים לאתרים, למצגות או לחומרי שיווק שיוצג עליהם טקסט.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
| קומפוזיציה מינימליסטית שכוללת עלה מייפל אדום אחד ועדין שממוקם בפינה השמאלית התחתונה של הפריים. הרקע הוא קנבס גדול וריק בצבע שמנת, שיוצר שטח שלילי משמעותי לטקסט. תאורה רכה ומפוזרת מלמעלה משמאל. תמונה מרובעת. |
|
אומנות רציפה (פאנל קומיקס / סטוריבורד)
הוא מתבסס על עקביות הדמויות ותיאור הסצנה כדי ליצור חלוניות לסיפור חזותי. כדי לקבל תוצאות מדויקות של טקסט ויכולת סיפור סיפורים, ההנחיות האלה פועלות הכי טוב עם Gemini 3 Pro ועם גרסת הטרום-השקה של Gemini 3.1 Flash Image.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
|
תמונת קלט:
הנחיה: צור קומיקס עם 3 פאנלים בסגנון אמנות נואר מחוספס עם דיו שחור ולבן בניגודיות גבוהה. הוספת הדמות לסצנה הומוריסטית. |
|
עיגון באמצעות חיפוש Google
אפשר להשתמש בחיפוש Google כדי ליצור תמונות על סמך מידע עדכני או מידע בזמן אמת. האפשרות הזו שימושית לחדשות, למזג האוויר ולנושאים אחרים שחשובים בזמן אמת.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
| תיצור גרפיקה פשוטה אבל מסוגננת של משחק ארסנל מאתמול בלילה בליגת האלופות |
|
הנחיות לעריכת תמונות
בדוגמאות האלה אפשר לראות איך מספקים תמונות לצד הנחיות טקסט כדי לערוך תמונות, ליצור קומפוזיציות ולהעביר סגנונות.
הוספה והסרה של רכיבים
צריך לספק תמונה ולתאר את השינוי. המודל יתאים לסגנון, לתאורה ולפרספקטיבה של התמונה המקורית.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
|
תמונת קלט:
הנחיה: באמצעות התמונה שסיפקתי של החתול שלי, תוסיף בבקשה כובע קוסם קטן וסרוג על הראש שלו. אני רוצה שהחתול ייראה כאילו הוא יושב בנוחות ושהתאורה תהיה רכה כמו בתמונה. |
|
ציור ומחיקה (סימון סמנטי)
אתם יכולים להגדיר 'מסכה' בשיחה כדי לערוך חלק ספציפי בתמונה בלי לשנות את שאר התמונה.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
|
תמונת קלט:
הנחיה: באמצעות התמונה שסופקה של סלון, תשנה רק את הספה הכחולה לספה בסגנון וינטג', ספת צ'סטרפילד מעור חום. שאר החדר, כולל הכריות על הספה והתאורה, יישארו ללא שינוי. |
|
העברת סגנון
מספקים תמונה ומבקשים מהמודל ליצור מחדש את התוכן שלה בסגנון אמנותי אחר.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
|
תמונת קלט:
הנחיה: תן לתמונה שצירפתי של רחוב בעיר מודרנית בלילה סגנון אומנותי כמו בציור 'ליל כוכבים' של וינסנט ואן גוך. שמור על הקומפוזיציה המקורית של הבניינים והמכוניות, אבל צור את כל האלמנטים באמצעות משיכות מכחול עבות ומערבולות, ופלטת צבעים דרמטית של כחולים עמוקים וצהובים בהירים. |
|
קומפוזיציה מתקדמת: שילוב של כמה תמונות
אתם יכולים לספק כמה תמונות כהקשר כדי ליצור סצנה מורכבת חדשה. האפשרות הזו מושלמת ליצירת מוקאפים של מוצרים או קולאז'ים יצירתיים.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
|
תמונות קלט:
הנחיה: תיצור תמונה מקצועית של אופנה למסחר אלקטרוני. קח את השמלה הכחולה עם הדוגמה הפרחונית מהתמונה הראשונה ותן לאישה מהתמונה השנייה ללבוש אותה. תיצור תמונה ריאליסטית של אישה לבושה בשמלה, כשהתאורה והצללים מותאמים לסביבה החיצונית. |
|
שמירה על פרטים ברמת דיוק גבוהה
כדי לוודא שפרטים חשובים (כמו פנים או לוגו) יישמרו במהלך העריכה, כדאי לתאר אותם בפירוט רב יחד עם בקשת העריכה.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
|
תמונות קלט:
הנחיה: צלם את התמונה הראשונה של האישה עם שיער חום, עיניים כחולות והבעה ניטרלית. תוסיף את הלוגו מהתמונה השנייה לחולצת הטריקו השחורה שלה. חשוב לוודא שתווי הפנים של האישה לא משתנים בכלל. הלוגו צריך להיראות כאילו הוא הודפס על הבד באופן טבעי, בהתאם לקפלים של החולצה. |
|
להפיח חיים במשהו
מעלים סקיצה או ציור ומבקשים מהמודל לשפר אותם לתמונה סופית.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
|
תמונת קלט:
הנחיה: תהפוך את הרישום הגס הזה בעיפרון של מכונית עתידנית לתמונה מלוטשת של מכונית קונספט מוכנה בחדר תצוגה. שומרים על הקווים החלקים והפרופיל הנמוך מהסקיצה, אבל מוסיפים צבע כחול מתכתי ותאורה היקפית בצבע ניאון. |
|
דמויות עקביות: תצוגת 360
אתם יכולים ליצור תצוגות של דמות ב-360 מעלות על ידי הזנת הנחיות חוזרות לזוויות שונות. כדי לקבל את התוצאות הטובות ביותר, כדאי לכלול בהנחיות הבאות תמונות שנוצרו בעבר כדי לשמור על עקביות. בתנוחות מורכבות, כדאי לכלול תמונה לדוגמה של התנוחה הרצויה.
| הנחיה | פלט שנוצר באמצעות AI |
|---|---|
|
תמונת קלט:
הנחיה: תמונה של גבר בסטודיו על רקע לבן, בפרופיל, מסתכל ימינה |
|
שיטות מומלצות
כדי לשפר את התוצאות שלכם מרמה טובה לרמה מצוינת, כדאי לשלב את האסטרטגיות המקצועיות האלה בתהליך העבודה.
- להיות ספציפיים מאוד: ככל שתספקו יותר פרטים, כך תהיה לכם יותר שליטה. במקום לכתוב "שריון פנטזיה", כדאי לתאר אותו: "שריון לוחות אלפי מעוטר, עם דוגמאות של עלי כסף חרוטים, צווארון גבוה ומגני כתפיים בצורת כנפי בז".
- הוספת הקשר וכוונת השימוש: חשוב להסביר את המטרה של התמונה. ההבנה של המודל לגבי ההקשר תשפיע על הפלט הסופי. לדוגמה, ההנחיה "תיצור לוגו למותג טיפוח עור יוקרתי ומינימליסטי" תניב תוצאות טובות יותר מההנחיה "תיצור לוגו".
- איטרציה ושיפור: אל תצפו לקבל תמונה מושלמת בניסיון הראשון. אפשר להשתמש באופי השיחתי של המודל כדי לבצע שינויים קטנים. אפשר להוסיף שאילתות המשך כמו "זה נהדר, אבל אפשר להפוך את התאורה לקצת יותר חמה?" או "תשאיר הכול כמו שזה, אבל תשנה את הבעת הפנים של הדמות כך שתיראה יותר רצינית".
- שימוש בהוראות מפורטות: בסצנות מורכבות עם הרבה אלמנטים, כדאי לחלק את ההנחיה לשלבים. "קודם, תיצור רקע של יער שליו ומעורפל עם שחר. אחר כך, בחזית, תוסיף מזבח אבן עתיק מכוסה טחב. לבסוף, מניחים חרב אחת זוהרת על המזבח".
- משתמשים בהנחיות שליליות סמנטיות: במקום לכתוב "no cars" (בלי מכוניות), מתארים את הסצנה הרצויה בצורה חיובית: "an empty, deserted street with no signs of traffic" (רחוב ריק ושומם ללא סימני תנועה).
- שליטה במצלמה: שימוש בשפה צילומית וקולנועית כדי לשלוט בקומפוזיציה. מונחים כמו
wide-angle shot,macro shot,low-angle perspective.
מגבלות
- כדי לקבל את הביצועים הכי טובים, מומלץ להשתמש בשפות הבאות: EN, ar-EG, de-DE, es-MX, fr-FR, hi-IN, id-ID, it-IT, ja-JP, ko-KR, pt-BR, ru-RU, ua-UA, vi-VN, zh-CN.
- יצירת תמונות לא תומכת בקלט אודיו או וידאו.
- המודל לא תמיד יפיק בדיוק את מספר התמונות שהמשתמש ביקש במפורש.
gemini-2.5-flash-imageעובד הכי טוב עם עד 3 תמונות כקלט, ואילוgemini-3-pro-image-previewתומך ב-5 תמונות באיכות גבוהה, ועד 14 תמונות בסך הכול. gemini-3.1-flash-image-previewתומך בדמיון של עד 4 תווים ובדיוק של עד 10 אובייקטים בתהליך עבודה יחיד.- כשמבקשים מ-Gemini ליצור טקסט לתמונה, מומלץ קודם ליצור את הטקסט ואז לבקש תמונה עם הטקסט.
gemini-3.1-flash-image-previewבשלב הזה, עיגון באמצעות חיפוש Google לא תומך בשימוש בתמונות של אנשים מהעולם האמיתי מחיפוש באינטרנט.- כל התמונות שנוצרות כוללות סימן מים של SynthID.
הגדרות אופציונליות
אפשר גם להגדיר את אופני התגובה ויחס הגובה-רוחב של הפלט של המודל בשדה config של קריאות generate_content.
סוגי פלט
כברירת מחדל, המודל מחזיר תשובות של טקסט ותמונות (כלומר, response_modalities=['Text', 'Image']). אפשר להגדיר את התשובה כך שתכלול רק תמונות בלי טקסט באמצעות response_modalities=['Image'].
Python
response = client.models.generate_content(
model="gemini-3.1-flash-image-preview",
contents=[prompt],
config=types.GenerateContentConfig(
response_modalities=['Image']
)
)
JavaScript
const response = await ai.models.generateContent({
model: "gemini-3.1-flash-image-preview",
contents: prompt,
config: {
responseModalities: ['Image']
}
});
Go
result, _ := client.Models.GenerateContent(
ctx,
"gemini-3.1-flash-image-preview",
genai.Text("Create a picture of a nano banana dish in a " +
" fancy restaurant with a Gemini theme"),
&genai.GenerateContentConfig{
ResponseModalities: "Image",
},
)
Java
response = client.models.generateContent(
"gemini-3.1-flash-image-preview",
prompt,
GenerateContentConfig.builder()
.responseModalities("IMAGE")
.build());
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [
{"text": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"}
]
}],
"generationConfig": {
"responseModalities": ["Image"]
}
}'
יחסי גובה-רוחב וגודל תמונה
כברירת מחדל, המודל מתאים את גודל תמונת הפלט לגודל תמונת הקלט, או יוצר ריבועים ביחס של 1:1.
אפשר לשלוט ביחס הגובה-רוחב של תמונת הפלט באמצעות השדה aspect_ratio
שמופיע בקטע response_format בבקשת התשובה, כמו שמוצג כאן:
Python
# For gemini-2.5-flash-image
response = client.models.generate_content(
model="gemini-2.5-flash-image",
contents=[prompt],
config=types.GenerateContentConfig(
response_format={"image": {aspect_ratio: "16:9",}}
)
)
# For gemini-3.1-flash-image-preview and gemini-3-pro-image-preview
response = client.models.generate_content(
model="gemini-3.1-flash-image-preview",
contents=[prompt],
config=types.GenerateContentConfig(
response_format={"image": {aspect_ratio: "16:9", image_size: "2K",}}
)
)
JavaScript
// For gemini-2.5-flash-image
const response = await ai.models.generateContent({
model: "gemini-2.5-flash-image",
contents: prompt,
config: {
responseFormat: {
image: {
aspectRatio: "16:9",
}
},
}
});
// For gemini-3.1-flash-image-preview and gemini-3-pro-image-preview
const response_gemini3 = await ai.models.generateContent({
model: "gemini-3.1-flash-image-preview",
contents: prompt,
config: {
responseFormat: {
image: {
aspectRatio: "16:9",
imageSize: "2K",
}
},
}
});
Go
// For gemini-2.5-flash-image
result, _ := client.Models.GenerateContent(
ctx,
"gemini-2.5-flash-image",
genai.Text("Create a picture of a nano banana dish in a " +
" fancy restaurant with a Gemini theme"),
&genai.GenerateContentConfig{
ImageConfig: &genai.ImageConfig{
AspectRatio: "16:9",
},
}
)
// For gemini-3.1-flash-image-preview and gemini-3-pro-image-preview
result_gemini3, _ := client.Models.GenerateContent(
ctx,
"gemini-3.1-flash-image-preview",
genai.Text("Create a picture of a nano banana dish in a " +
" fancy restaurant with a Gemini theme"),
&genai.GenerateContentConfig{
ImageConfig: &genai.ImageConfig{
AspectRatio: "16:9",
ImageSize: "2K",
},
}
)
Java
// For gemini-2.5-flash-image
response = client.models.generateContent(
"gemini-2.5-flash-image",
prompt,
GenerateContentConfig.builder()
.imageConfig(ImageConfig.builder()
.aspectRatio("16:9")
.build())
.build());
// For gemini-3.1-flash-image-preview and gemini-3-pro-image-preview
response_gemini3 = client.models.generateContent(
"gemini-3.1-flash-image-preview",
prompt,
GenerateContentConfig.builder()
.imageConfig(ImageConfig.builder()
.aspectRatio("16:9")
.imageSize("2K")
.build())
.build());
REST
# For gemini-2.5-flash-image
curl -s -X POST \
"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' \
-d '{
"contents": [{
"parts": [
{"text": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"}
]
}],
"generationConfig": {
"responseFormat": {
"image": {
"aspectRatio": "16:9"
}
}
}
}'
# For gemini-3-pro-image-preview
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"contents": [{
"parts": [
{"text": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"}
]
}],
"generationConfig": {
"responseFormat": {
"image": {
"aspectRatio": "16:9",
"imageSize": "2K"
}
}
}
}'
בטבלאות הבאות מפורטים היחסים השונים שזמינים וגודל התמונה שנוצרת:
3.1 Flash Image Preview
| יחס גובה-רוחב | רזולוציה של 512 | 0.5K טוקנים | רזולוציית 1K | 1K טוקנים | רזולוציית 2K | 2,000 טוקנים | רזולוציית 4K | 4K טוקנים |
|---|---|---|---|---|---|---|---|---|
| 1:1 | 512x512 | 747 | 1024x1024 | 1120 | 2048x2048 | 1680 | 4096x4096 | 2520 |
| 1:4 | 256x1024 | 747 | 512x2048 | 1120 | 1024x4096 | 1680 | 2048x8192 | 2520 |
| 1:8 | 192x1536 | 747 | 384x3072 | 1120 | 768x6144 | 1680 | 1536x12288 | 2520 |
| 2:3 | 424x632 | 747 | 848x1264 | 1120 | 1696x2528 | 1680 | 3392x5056 | 2520 |
| 3:2 | 632x424 | 747 | 1264x848 | 1120 | 2528x1696 | 1680 | 5056x3392 | 2520 |
| 3:4 | 448x600 | 747 | 896x1200 | 1120 | 1792x2400 | 1680 | 3584x4800 | 2520 |
| 4:1 | 1024x256 | 747 | 2048x512 | 1120 | 4096x1024 | 1680 | 8192x2048 | 2520 |
| 4:3 | 600x448 | 747 | 1,200x896 | 1120 | 2400x1792 | 1680 | 4800x3584 | 2520 |
| 4:5 | 464x576 | 747 | 928x1152 | 1120 | 1856x2304 | 1680 | 3712x4608 | 2520 |
| 5:4 | 576x464 | 747 | 1152x928 | 1120 | 2304x1856 | 1680 | 4608x3712 | 2520 |
| 8:1 | 1536x192 | 747 | 3072x384 | 1120 | 6,144x768 | 1680 | 12288x1536 | 2520 |
| 9:16 | 384x688 | 747 | 768 x 1376 | 1120 | 1536x2752 | 1680 | 3072x5504 | 2520 |
| 16:9 | 688x384 | 747 | 1376x768 | 1120 | 2752x1536 | 1680 | 5504x3072 | 2520 |
| 21:9 | 792x168 | 747 | 1584x672 | 1120 | 3,168x1,344 | 1680 | 6336x2688 | 2520 |
תצוגה מקדימה של תמונה ב-3 Pro
| יחס גובה-רוחב | רזולוציית 1K | 1K טוקנים | רזולוציית 2K | 2,000 טוקנים | רזולוציית 4K | 4K טוקנים |
|---|---|---|---|---|---|---|
| 1:1 | 1024x1024 | 1120 | 2048x2048 | 1120 | 4096x4096 | 2000 |
| 2:3 | 848x1264 | 1120 | 1696x2528 | 1120 | 3392x5056 | 2000 |
| 3:2 | 1264x848 | 1120 | 2528x1696 | 1120 | 5056x3392 | 2000 |
| 3:4 | 896x1200 | 1120 | 1792x2400 | 1120 | 3584x4800 | 2000 |
| 4:3 | 1,200x896 | 1120 | 2400x1792 | 1120 | 4800x3584 | 2000 |
| 4:5 | 928x1152 | 1120 | 1856x2304 | 1120 | 3712x4608 | 2000 |
| 5:4 | 1152x928 | 1120 | 2304x1856 | 1120 | 4608x3712 | 2000 |
| 9:16 | 768 x 1376 | 1120 | 1536x2752 | 1120 | 3072x5504 | 2000 |
| 16:9 | 1376x768 | 1120 | 2752x1536 | 1120 | 5504x3072 | 2000 |
| 21:9 | 1584x672 | 1120 | 3,168x1,344 | 1120 | 6336x2688 | 2000 |
Gemini 2.5 Flash Image
| יחס גובה-רוחב | רזולוציה | טוקנים |
|---|---|---|
| 1:1 | 1024x1024 | 1290 |
| 2:3 | 832x1248 | 1290 |
| 3:2 | 1248x832 | 1290 |
| 3:4 | 864x1184 | 1290 |
| 4:3 | 1184x864 | 1290 |
| 4:5 | 896x1152 | 1290 |
| 5:4 | 1152x896 | 1290 |
| 9:16 | 768x1344 | 1290 |
| 16:9 | 1344x768 | 1290 |
| 21:9 | 1536x672 | 1290 |
בחירת מודל
בוחרים את המודל שהכי מתאים לתרחיש הספציפי שלכם.
Gemini 3.1 Flash Image Preview (Nano Banana 2 Preview) הוא המודל המומלץ ליצירת תמונות, כי הוא מציע את הביצועים הכי טובים ואת האיזון הכי טוב בין עלות לזמן אחזור. פרטים נוספים זמינים בדף המחירים והיכולות של המודל.
Gemini 3 Pro Image Preview (תצוגה מקדימה של Nano Banana Pro) מיועד ליצירת נכסים מקצועיים ולהוראות מורכבות. המודל הזה כולל עיגון לנתונים מהעולם האמיתי באמצעות חיפוש Google, תהליך ברירת מחדל של 'העמקה' שמשפר את הקומפוזיציה לפני היצירה, ויכול ליצור תמונות ברזולוציה של עד 4K. פרטים נוספים זמינים בדף המחירים והיכולות של המודל.
Gemini 2.5 Flash Image (Nano Banana) מיועד ליצירת תמונות במהירות וביעילות. המודל הזה מותאם למשימות שדורשות נפח גבוה וזמן טעינה קצר, והוא יוצר תמונות ברזולוציה של 1,024 פיקסלים. פרטים נוספים זמינים בדף המחירים והיכולות של המודל.
מתי כדאי להשתמש ב-Imagen
בנוסף ליכולות המובנות של Gemini ליצירת תמונות, אפשר גם לגשת אל Imagen, המודל הייעודי שלנו ליצירת תמונות, דרך Gemini API.
Imagen 4 הוא המודל המומלץ להתחלת יצירת תמונות באמצעות Imagen. בוחרים ב-Imagen 4 Ultra לתרחישי שימוש מתקדמים או כשצריך את איכות התמונה הכי טובה (שימו לב שאפשר ליצור רק תמונה אחת בכל פעם).
המאמרים הבאים
- במדריך המתכונים יש עוד דוגמאות ודוגמאות קוד.
- במדריך ל-Veo מוסבר איך ליצור סרטונים באמצעות Gemini API.
- מידע נוסף על מודלים של Gemini זמין במאמר מודלים של Gemini.