میتوانید از مدل Gemini «تصویر» بخواهید بااستفاده از پیاموارههای نوشتاری و پیاموارههای نوشتاری و فایلی، تصویر تولید و ویرایش کند. وقتی از Firebase AI Logic استفاده میکنید، میتوانید این درخواست را مستقیماً از برنامهتان انجام دهید.
با این قابلیت، میتوانید کارهایی ازاینقبیل انجام دهید:
تصاویر را ازطریق مکالمه با زبان طبیعی بهصورت تکراری تولید کنید و تصاویر را درحالیکه یکپارچگی و بافت را حفظ میکنید اصلاح کنید.
تصاویری با پرداز زدن نوشتار با کیفیت بالا، ازجمله رشتههای طولانی نوشتار، تولید کنید.
برونداد نوشتار-تصویر درهمتنیده تولید کنید. برای مثال، پست وبلاگی با نوشتار و تصاویر در یک نوبت. قبلاً، این کار مستلزم بههم پیوستن چندین مدل بود.
بااستفاده از دانش جهانی و قابلیتهای استدلال Gemini، تصویر تولید کنید.
میتوانید روش پاسخ را برای درخواستتان پیکربندی کنید تا مدل فقط تصویر یا هم تصویر و هم نوشتار تولید کند. در ادامه این صفحه، فهرست کاملی از ویژگیهای پشتیبانیشده (همراه با پیاموارههای نمونه) را پیدا کنید.
رفتن به کد نوشتار به تصویر رفتن به کد نوشتار و تصاویر درهمآمیخته
رفتن به کد برای ویرایش تصویر رفتن به کد برای ویرایش تکرارشونده تصویر
|
برای گزینههای بیشتر کار با تصاویر، راهنماهای دیگر را ببینید تحلیل تصاویر تحلیل تصاویر در دستگاه تولید برونداد ساختاریافته |
قبل از شروع
|
روی ارائهدهنده Gemini API خود کلیک کنید تا محتوا و کد مخصوص ارائهدهنده را در این صفحه مشاهده کنید. |
اگر هنوز این کار را نکردهاید،
راهنمای شروع به کار را تکمیل کنید. این راهنما نحوه
راهاندازی پروژه Firebase، متصل کردن برنامه به Firebase، افزودن کیت توسعه نرمافزار،
مقداردهی اولیه سرویس زیرینه برای ارائهدهنده Gemini API انتخابی، و
ایجاد نمونه GenerativeModel را شرح میدهد.
برای آزمایش و تکرار پیاموارههایتان، توصیه میکنیم از Google AI Studio استفاده کنید.
مدلهایی که از این قابلیت پشتیبانی میکنند
-
gemini-3-pro-image(با نام مستعار «Nano Banana Pro») gemini-3.1-flash-image(با نام مستعار «Nano Banana 2»)-
gemini-3.1-flash-lite-image(با نام مستعار «Nano Banana 2 Lite»)
مدلهای Gemini 2.5 تولیدکننده تصویر از این قابلیت پشتیبانی میکنند، اما همه آنها منسوخ شدهاند.
تولید و ویرایش کردن تصویرها
بااستفاده از مدل Gemini میتوانید تصویر تولید و ویرایش کنید.
تولید کردن تصویر (ورودی فقط نوشتار)
|
پیشاز امتحان کردن این نمونه، بخش
پیشاز شروع این راهنما را تکمیل کنید
تا پروژه و برنامهتان را راهاندازی کنید. در آن بخش، همچنین روی دکمهای برای ارائهدهنده Gemini API انتخابیتان کلیک خواهید کرد تا محتوای مختص ارائهدهنده را در این صفحه ببینید. |
میتوانید از مدل Gemini تصویر بخواهید با پیامواره نوشتاری تصویر تولید کند.
نمونه GenerativeModel ایجاد کن،
روش پاسخ IMAGE را در پیکربندی مدل بگنجان،
و generateContent را فرا بخوان.
Swift
import FirebaseAILogic
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
let generativeModel = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "gemini-3.1-flash-image",
// Configure the model to respond with images only.
generationConfig: GenerationConfig(responseModalities: [.image])
)
// Provide a text prompt instructing the model to generate an image
let prompt = "Generate an image of the Eiffel tower with fireworks in the background."
// To generate an image, call `generateContent` with the text input
let response = try await model.generateContent(prompt)
// Handle the generated image
guard let inlineDataPart = response.inlineDataParts.first else {
fatalError("No image data in response.")
}
guard let uiImage = UIImage(data: inlineDataPart.data) else {
fatalError("Failed to convert data to UIImage.")
}
Kotlin
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "gemini-3.1-flash-image",
// Configure the model to respond with images only.
generationConfig = generationConfig {
responseModalities = listOf(ResponseModality.IMAGE) }
)
// Provide a text prompt instructing the model to generate an image
val prompt = "Generate an image of the Eiffel tower with fireworks in the background."
// To generate image output, call `generateContent` with the text input
val generatedImageAsBitmap = model.generateContent(prompt)
// Handle the generated image
.candidates.first().content.parts.filterIsInstance<ImagePart>().firstOrNull()?.image
Java
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI()).generativeModel(
"gemini-3.1-flash-image",
// Configure the model to respond with images only.
new GenerationConfig.Builder()
.setResponseModalities(Arrays.asList(ResponseModality.IMAGE))
.build()
);
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// Provide a text prompt instructing the model to generate an image
Content prompt = new Content.Builder()
.addText("Generate an image of the Eiffel Tower with fireworks in the background.")
.build();
// To generate an image, call `generateContent` with the text input
ListenableFuture<GenerateContentResponse> response = model.generateContent(prompt);
Futures.addCallback(response, new FutureCallback<GenerateContentResponse>() {
@Override
public void onSuccess(GenerateContentResponse result) {
// iterate over all the parts in the first candidate in the result object
for (Part part : result.getCandidates().get(0).getContent().getParts()) {
if (part instanceof ImagePart) {
ImagePart imagePart = (ImagePart) part;
// The returned image as a bitmap
Bitmap generatedImageAsBitmap = imagePart.getImage();
break;
}
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend, ResponseModality } from "firebase/ai";
// TODO(developer): Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `GenerativeModel` instance with a model that supports your use case
const model = getGenerativeModel(ai, {
model: "gemini-3.1-flash-image",
// Configure the model to respond with images only.
generationConfig: {
responseModalities: [ResponseModality.IMAGE],
},
});
// Provide a text prompt instructing the model to generate an image
const prompt = 'Generate an image of the Eiffel Tower with fireworks in the background.';
// To generate an image, call `generateContent` with the text input
const result = model.generateContent(prompt);
// Handle the generated image
try {
const inlineDataParts = result.response.inlineDataParts();
if (inlineDataParts?.[0]) {
const image = inlineDataParts[0].inlineData;
console.log(image.mimeType, image.data);
}
} catch (err) {
console.error('Prompt or candidate was blocked:', err);
}
Dart
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
final model = FirebaseAI.googleAI().generativeModel(
model: 'gemini-3.1-flash-image',
// Configure the model to respond with images only.
generationConfig: GenerationConfig(responseModalities: [ResponseModalities.image]),
);
// Provide a text prompt instructing the model to generate an image
final prompt = [Content.text('Generate an image of the Eiffel Tower with fireworks in the background.')];
// To generate an image, call `generateContent` with the text input
final response = await model.generateContent(prompt);
if (response.inlineDataParts.isNotEmpty) {
final imageBytes = response.inlineDataParts[0].bytes;
// Process the image
} else {
// Handle the case where no images were generated
print('Error: No images were generated.');
}
Unity
using Firebase;
using Firebase.AI;
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetGenerativeModel(
modelName: "gemini-3.1-flash-image",
// Configure the model to respond with images only.
generationConfig: new GenerationConfig(
responseModalities: new[] { ResponseModality.Image })
);
// Provide a text prompt instructing the model to generate an image
var prompt = "Generate an image of the Eiffel Tower with fireworks in the background.";
// To generate an image, call `GenerateContentAsync` with the text input
var response = await model.GenerateContentAsync(prompt);
var text = response.Text;
if (!string.IsNullOrWhiteSpace(text)) {
// Do something with the text
}
// Handle the generated image
var imageParts = response.Candidates.First().Content.Parts
.OfType<ModelContent.InlineDataPart>()
.Where(part => part.MimeType == "image/png");
foreach (var imagePart in imageParts) {
// Load the Image into a Unity Texture2D object
UnityEngine.Texture2D texture2D = new(2, 2);
if (texture2D.LoadImage(imagePart.Data.ToArray())) {
// Do something with the image
}
}
تولید کردن نوشتار و تصویر درهمتنیده
|
پیشاز امتحان کردن این نمونه، بخش
پیشاز شروع این راهنما را تکمیل کنید
تا پروژه و برنامهتان را راهاندازی کنید. در آن بخش، همچنین روی دکمهای برای ارائهدهنده Gemini API انتخابیتان کلیک خواهید کرد تا محتوای مختص ارائهدهنده را در این صفحه ببینید. |
میتوانید از مدل Gemini «تصویر» بخواهید که تصاویر درهمتنیده با پاسخهای نوشتاریاش تولید کند. برای مثال، میتوانید تصویرهایی از ظاهر هر مرحله از دستور پخت تولیدشده را همراه با دستورالعملهای آن مرحله تولید کنید، و لازم نیست درخواستهای جداگانهای به مدل یا مدلهای مختلف ارائه دهید.
نمونه GenerativeModel ایجاد کن،
شیوههای پاسخ TEXT و IMAGE را در پیکربندی مدل بگنجان،
و generateContent را فرا بخوان.
Swift
import FirebaseAILogic
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
let generativeModel = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "gemini-3.1-flash-image",
// Configure the model to respond with text and images.
generationConfig: GenerationConfig(responseModalities: [.text, .image])
)
// Provide a text prompt instructing the model to generate interleaved text and images
let prompt = """
Generate an illustrated recipe for a paella.
Create images to go alongside the text as you generate the recipe
"""
// To generate interleaved text and images, call `generateContent` with the text input
let response = try await model.generateContent(prompt)
// Handle the generated text and image
guard let candidate = response.candidates.first else {
fatalError("No candidates in response.")
}
for part in candidate.content.parts {
switch part {
case let textPart as TextPart:
// Do something with the generated text
let text = textPart.text
case let inlineDataPart as InlineDataPart:
// Do something with the generated image
guard let uiImage = UIImage(data: inlineDataPart.data) else {
fatalError("Failed to convert data to UIImage.")
}
default:
fatalError("Unsupported part type: \(part)")
}
}
Kotlin
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "gemini-3.1-flash-image",
// Configure the model to respond with text and images.
generationConfig = generationConfig {
responseModalities = listOf(ResponseModality.TEXT, ResponseModality.IMAGE) }
)
// Provide a text prompt instructing the model to generate interleaved text and images
val prompt = """
Generate an illustrated recipe for a paella.
Create images to go alongside the text as you generate the recipe
""".trimIndent()
// To generate interleaved text and images, call `generateContent` with the text input
val responseContent = model.generateContent(prompt).candidates.first().content
// The response will contain image and text parts interleaved
for (part in responseContent.parts) {
when (part) {
is ImagePart -> {
// ImagePart as a bitmap
val generatedImageAsBitmap: Bitmap? = part.asImageOrNull()
}
is TextPart -> {
// Text content from the TextPart
val text = part.text
}
}
}
Java
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI()).generativeModel(
"gemini-3.1-flash-image",
// Configure the model to respond with text and images.
new GenerationConfig.Builder()
.setResponseModalities(Arrays.asList(ResponseModality.TEXT, ResponseModality.IMAGE))
.build()
);
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// Provide a text prompt instructing the model to generate interleaved text and images
Content prompt = new Content.Builder()
.addText("Generate an illustrated recipe for a paella.\n" +
"Create images to go alongside the text as you generate the recipe")
.build();
// To generate interleaved text and images, call `generateContent` with the text input
ListenableFuture<GenerateContentResponse> response = model.generateContent(prompt);
Futures.addCallback(response, new FutureCallback<GenerateContentResponse>() {
@Override
public void onSuccess(GenerateContentResponse result) {
Content responseContent = result.getCandidates().get(0).getContent();
// The response will contain image and text parts interleaved
for (Part part : responseContent.getParts()) {
if (part instanceof ImagePart) {
// ImagePart as a bitmap
Bitmap generatedImageAsBitmap = ((ImagePart) part).getImage();
} else if (part instanceof TextPart){
// Text content from the TextPart
String text = ((TextPart) part).getText();
}
}
}
@Override
public void onFailure(Throwable t) {
System.err.println(t);
}
}, executor);
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend, ResponseModality } from "firebase/ai";
// TODO(developer): Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `GenerativeModel` instance with a model that supports your use case
const model = getGenerativeModel(ai, {
model: "gemini-3.1-flash-image",
// Configure the model to respond with text and images.
generationConfig: {
responseModalities: [ResponseModality.TEXT, ResponseModality.IMAGE],
},
});
// Provide a text prompt instructing the model to generate interleaved text and images
const prompt = 'Generate an illustrated recipe for a paella.\n.' +
'Create images to go alongside the text as you generate the recipe';
// To generate interleaved text and images, call `generateContent` with the text input
const result = await model.generateContent(prompt);
// Handle the generated text and image
try {
const response = result.response;
if (response.candidates?.[0].content?.parts) {
for (const part of response.candidates?.[0].content?.parts) {
if (part.text) {
// Do something with the text
console.log(part.text)
}
if (part.inlineData) {
// Do something with the image
const image = part.inlineData;
console.log(image.mimeType, image.data);
}
}
}
} catch (err) {
console.error('Prompt or candidate was blocked:', err);
}
Dart
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
final model = FirebaseAI.googleAI().generativeModel(
model: 'gemini-3.1-flash-image',
// Configure the model to respond with text and images.
generationConfig: GenerationConfig(responseModalities: [ResponseModalities.text, ResponseModalities.image]),
);
// Provide a text prompt instructing the model to generate interleaved text and images
final prompt = [Content.text(
'Generate an illustrated recipe for a paella\n ' +
'Create images to go alongside the text as you generate the recipe'
)];
// To generate interleaved text and images, call `generateContent` with the text input
final response = await model.generateContent(prompt);
// Handle the generated text and image
final parts = response.candidates.firstOrNull?.content.parts
if (parts.isNotEmpty) {
for (final part in parts) {
if (part is TextPart) {
// Do something with text part
final text = part.text
}
if (part is InlineDataPart) {
// Process image
final imageBytes = part.bytes
}
}
} else {
// Handle the case where no images were generated
print('Error: No images were generated.');
}
Unity
using Firebase;
using Firebase.AI;
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetGenerativeModel(
modelName: "gemini-3.1-flash-image",
// Configure the model to respond with text and images.
generationConfig: new GenerationConfig(
responseModalities: new[] { ResponseModality.Text, ResponseModality.Image })
);
// Provide a text prompt instructing the model to generate interleaved text and images
var prompt = "Generate an illustrated recipe for a paella \n" +
"Create images to go alongside the text as you generate the recipe";
// To generate interleaved text and images, call `GenerateContentAsync` with the text input
var response = await model.GenerateContentAsync(prompt);
// Handle the generated text and image
foreach (var part in response.Candidates.First().Content.Parts) {
if (part is ModelContent.TextPart textPart) {
if (!string.IsNullOrWhiteSpace(textPart.Text)) {
// Do something with the text
}
} else if (part is ModelContent.InlineDataPart dataPart) {
if (dataPart.MimeType == "image/png") {
// Load the Image into a Unity Texture2D object
UnityEngine.Texture2D texture2D = new(2, 2);
if (texture2D.LoadImage(dataPart.Data.ToArray())) {
// Do something with the image
}
}
}
}
ویرایش تصاویر (ورودی نوشتار و تصویر)
|
پیشاز امتحان کردن این نمونه، بخش
پیشاز شروع این راهنما را تکمیل کنید
تا پروژه و برنامهتان را راهاندازی کنید. در آن بخش، همچنین روی دکمهای برای ارائهدهنده Gemini API انتخابیتان کلیک خواهید کرد تا محتوای مختص ارائهدهنده را در این صفحه ببینید. |
میتوانید از مدل Gemini «تصویر» بخواهید تصاویر را با پیامواره نوشتاری و یک یا چند تصویر ویرایش کند.
نمونه GenerativeModel ایجاد کن،
روش پاسخ IMAGE را در پیکربندی مدل بگنجان،
و generateContent را فرا بخوان.
Swift
import FirebaseAILogic
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
let generativeModel = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "gemini-3.1-flash-image",
// Configure the model to respond with images only.
generationConfig: GenerationConfig(responseModalities: [.image])
)
// Provide an image for the model to edit
guard let image = UIImage(named: "scones") else { fatalError("Image file not found.") }
// Provide a text prompt instructing the model to edit the image
let prompt = "Edit this image to make it look like a cartoon"
// To edit the image, call `generateContent` with the image and text input
let response = try await model.generateContent(image, prompt)
// Handle the generated image
guard let inlineDataPart = response.inlineDataParts.first else {
fatalError("No image data in response.")
}
guard let uiImage = UIImage(data: inlineDataPart.data) else {
fatalError("Failed to convert data to UIImage.")
}
Kotlin
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "gemini-3.1-flash-image",
// Configure the model to respond with images only.
generationConfig = generationConfig {
responseModalities = listOf(ResponseModality.IMAGE) }
)
// Provide an image for the model to edit
val bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.scones)
// Provide a text prompt instructing the model to edit the image
val prompt = content {
image(bitmap)
text("Edit this image to make it look like a cartoon")
}
// To edit the image, call `generateContent` with the prompt (image and text input)
val generatedImageAsBitmap = model.generateContent(prompt)
// Handle the generated text and image
.candidates.first().content.parts.filterIsInstance<ImagePart>().firstOrNull()?.image
Java
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI()).generativeModel(
"gemini-3.1-flash-image",
// Configure the model to respond with images only.
new GenerationConfig.Builder()
.setResponseModalities(Arrays.asList(ResponseModality.IMAGE))
.build()
);
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// Provide an image for the model to edit
Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.scones);
// Provide a text prompt instructing the model to edit the image
Content promptcontent = new Content.Builder()
.addImage(bitmap)
.addText("Edit this image to make it look like a cartoon")
.build();
// To edit the image, call `generateContent` with the prompt (image and text input)
ListenableFuture<GenerateContentResponse> response = model.generateContent(promptcontent);
Futures.addCallback(response, new FutureCallback<GenerateContentResponse>() {
@Override
public void onSuccess(GenerateContentResponse result) {
// iterate over all the parts in the first candidate in the result object
for (Part part : result.getCandidates().get(0).getContent().getParts()) {
if (part instanceof ImagePart) {
ImagePart imagePart = (ImagePart) part;
Bitmap generatedImageAsBitmap = imagePart.getImage();
break;
}
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend, ResponseModality } from "firebase/ai";
// TODO(developer): Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `GenerativeModel` instance with a model that supports your use case
const model = getGenerativeModel(ai, {
model: "gemini-3.1-flash-image",
// Configure the model to respond with images only.
generationConfig: {
responseModalities: [ResponseModality.IMAGE],
},
});
// Prepare an image for the model to edit
async function fileToGenerativePart(file) {
const base64EncodedDataPromise = new Promise((resolve) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result.split(',')[1]);
reader.readAsDataURL(file);
});
return {
inlineData: { data: await base64EncodedDataPromise, mimeType: file.type },
};
}
// Provide a text prompt instructing the model to edit the image
const prompt = "Edit this image to make it look like a cartoon";
const fileInputEl = document.querySelector("input[type=file]");
const imagePart = await fileToGenerativePart(fileInputEl.files[0]);
// To edit the image, call `generateContent` with the image and text input
const result = await model.generateContent([prompt, imagePart]);
// Handle the generated image
try {
const inlineDataParts = result.response.inlineDataParts();
if (inlineDataParts?.[0]) {
const image = inlineDataParts[0].inlineData;
console.log(image.mimeType, image.data);
}
} catch (err) {
console.error('Prompt or candidate was blocked:', err);
}
Dart
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
final model = FirebaseAI.googleAI().generativeModel(
model: 'gemini-3.1-flash-image',
// Configure the model to respond with images only.
generationConfig: GenerationConfig(responseModalities: [ResponseModalities.image]),
);
// Prepare an image for the model to edit
final image = await File('scones.jpg').readAsBytes();
final imagePart = InlineDataPart('image/jpeg', image);
// Provide a text prompt instructing the model to edit the image
final prompt = TextPart("Edit this image to make it look like a cartoon");
// To edit the image, call `generateContent` with the image and text input
final response = await model.generateContent([
Content.multi([prompt,imagePart])
]);
// Handle the generated image
if (response.inlineDataParts.isNotEmpty) {
final imageBytes = response.inlineDataParts[0].bytes;
// Process the image
} else {
// Handle the case where no images were generated
print('Error: No images were generated.');
}
Unity
using Firebase;
using Firebase.AI;
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetGenerativeModel(
modelName: "gemini-3.1-flash-image",
// Configure the model to respond with images only.
generationConfig: new GenerationConfig(
responseModalities: new[] { ResponseModality.Image })
);
// Prepare an image for the model to edit
var imageFile = System.IO.File.ReadAllBytes(System.IO.Path.Combine(
UnityEngine.Application.streamingAssetsPath, "scones.jpg"));
var image = ModelContent.InlineData("image/jpeg", imageFile);
// Provide a text prompt instructing the model to edit the image
var prompt = ModelContent.Text("Edit this image to make it look like a cartoon.");
// To edit the image, call `GenerateContent` with the image and text input
var response = await model.GenerateContentAsync(new [] { prompt, image });
var text = response.Text;
if (!string.IsNullOrWhiteSpace(text)) {
// Do something with the text
}
// Handle the generated image
var imageParts = response.Candidates.First().Content.Parts
.OfType<ModelContent.InlineDataPart>()
.Where(part => part.MimeType == "image/png");
foreach (var imagePart in imageParts) {
// Load the Image into a Unity Texture2D object
Texture2D texture2D = new Texture2D(2, 2);
if (texture2D.LoadImage(imagePart.Data.ToArray())) {
// Do something with the image
}
}
بااستفاده از گپ چندنوبتی، تصاویر را تکرار و ویرایش کنید
|
پیشاز امتحان کردن این نمونه، بخش
پیشاز شروع این راهنما را تکمیل کنید
تا پروژه و برنامهتان را راهاندازی کنید. در آن بخش، همچنین روی دکمهای برای ارائهدهنده Gemini API انتخابیتان کلیک خواهید کرد تا محتوای مختص ارائهدهنده را در این صفحه ببینید. |
بااستفاده از گپ چندنوبتی، میتوانید با مدل تصویر Gemini درباره تصاویری که تولید میکند یا تصاویری که ارائه میدهید تکرار کنید.
نمونه GenerativeModel ایجاد کنید،
روش پاسخ IMAGE را در پیکربندی مدل خود بگنجانید،
و برای ارسال پیامهای کاربر جدید، startChat() و sendMessage() را فراخوانی کنید.
Swift
import FirebaseAILogic
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
let generativeModel = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "gemini-3.1-flash-image",
// Configure the model to respond with images only.
generationConfig: GenerationConfig(responseModalities: [.image])
)
// Initialize the chat
let chat = model.startChat()
guard let image = UIImage(named: "scones") else { fatalError("Image file not found.") }
// Provide an initial text prompt instructing the model to edit the image
let prompt = "Edit this image to make it look like a cartoon"
// To generate an initial response, send a user message with the image and text prompt
let response = try await chat.sendMessage(image, prompt)
// Inspect the generated image
guard let inlineDataPart = response.inlineDataParts.first else {
fatalError("No image data in response.")
}
guard let uiImage = UIImage(data: inlineDataPart.data) else {
fatalError("Failed to convert data to UIImage.")
}
// Follow up requests do not need to specify the image again
let followUpResponse = try await chat.sendMessage("But make it old-school line drawing style")
// Inspect the edited image after the follow up request
guard let followUpInlineDataPart = followUpResponse.inlineDataParts.first else {
fatalError("No image data in response.")
}
guard let followUpUIImage = UIImage(data: followUpInlineDataPart.data) else {
fatalError("Failed to convert data to UIImage.")
}
Kotlin
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "gemini-3.1-flash-image",
// Configure the model to respond with images only.
generationConfig = generationConfig {
responseModalities = listOf(ResponseModality.IMAGE) }
)
// Provide an image for the model to edit
val bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.scones)
// Create the initial prompt instructing the model to edit the image
val prompt = content {
image(bitmap)
text("Edit this image to make it look like a cartoon")
}
// Initialize the chat
val chat = model.startChat()
// To generate an initial response, send a user message with the image and text prompt
var response = chat.sendMessage(prompt)
// Inspect the returned image
var generatedImageAsBitmap = response
.candidates.first().content.parts.filterIsInstance<ImagePart>().firstOrNull()?.image
// Follow up requests do not need to specify the image again
response = chat.sendMessage("But make it old-school line drawing style")
generatedImageAsBitmap = response
.candidates.first().content.parts.filterIsInstance<ImagePart>().firstOrNull()?.image
Java
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI()).generativeModel(
"gemini-3.1-flash-image",
// Configure the model to respond with images only.
new GenerationConfig.Builder()
.setResponseModalities(Arrays.asList(ResponseModality.IMAGE))
.build()
);
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// Provide an image for the model to edit
Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.scones);
// Initialize the chat
ChatFutures chat = model.startChat();
// Create the initial prompt instructing the model to edit the image
Content prompt = new Content.Builder()
.setRole("user")
.addImage(bitmap)
.addText("Edit this image to make it look like a cartoon")
.build();
// To generate an initial response, send a user message with the image and text prompt
ListenableFuture<GenerateContentResponse> response = chat.sendMessage(prompt);
// Extract the image from the initial response
ListenableFuture<@Nullable Bitmap> initialRequest = Futures.transform(response, result -> {
for (Part part : result.getCandidates().get(0).getContent().getParts()) {
if (part instanceof ImagePart) {
ImagePart imagePart = (ImagePart) part;
return imagePart.getImage();
}
}
return null;
}, executor);
// Follow up requests do not need to specify the image again
ListenableFuture<GenerateContentResponse> modelResponseFuture = Futures.transformAsync(
initialRequest,
generatedImage -> {
Content followUpPrompt = new Content.Builder()
.addText("But make it old-school line drawing style")
.build();
return chat.sendMessage(followUpPrompt);
},
executor);
// Add a final callback to check the reworked image
Futures.addCallback(modelResponseFuture, new FutureCallback<GenerateContentResponse>() {
@Override
public void onSuccess(GenerateContentResponse result) {
for (Part part : result.getCandidates().get(0).getContent().getParts()) {
if (part instanceof ImagePart) {
ImagePart imagePart = (ImagePart) part;
Bitmap generatedImageAsBitmap = imagePart.getImage();
break;
}
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend, ResponseModality } from "firebase/ai";
// TODO(developer): Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `GenerativeModel` instance with a model that supports your use case
const model = getGenerativeModel(ai, {
model: "gemini-3.1-flash-image",
// Configure the model to respond with images only.
generationConfig: {
responseModalities: [ResponseModality.IMAGE],
},
});
// Prepare an image for the model to edit
async function fileToGenerativePart(file) {
const base64EncodedDataPromise = new Promise((resolve) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result.split(',')[1]);
reader.readAsDataURL(file);
});
return {
inlineData: { data: await base64EncodedDataPromise, mimeType: file.type },
};
}
const fileInputEl = document.querySelector("input[type=file]");
const imagePart = await fileToGenerativePart(fileInputEl.files[0]);
// Provide an initial text prompt instructing the model to edit the image
const prompt = "Edit this image to make it look like a cartoon";
// Initialize the chat
const chat = model.startChat();
// To generate an initial response, send a user message with the image and text prompt
const result = await chat.sendMessage([prompt, imagePart]);
// Request and inspect the generated image
try {
const inlineDataParts = result.response.inlineDataParts();
if (inlineDataParts?.[0]) {
// Inspect the generated image
const image = inlineDataParts[0].inlineData;
console.log(image.mimeType, image.data);
}
} catch (err) {
console.error('Prompt or candidate was blocked:', err);
}
// Follow up requests do not need to specify the image again
const followUpResult = await chat.sendMessage("But make it old-school line drawing style");
// Request and inspect the returned image
try {
const followUpInlineDataParts = followUpResult.response.inlineDataParts();
if (followUpInlineDataParts?.[0]) {
// Inspect the generated image
const followUpImage = followUpInlineDataParts[0].inlineData;
console.log(followUpImage.mimeType, followUpImage.data);
}
} catch (err) {
console.error('Prompt or candidate was blocked:', err);
}
Dart
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
final model = FirebaseAI.googleAI().generativeModel(
model: 'gemini-3.1-flash-image',
// Configure the model to respond with images only.
generationConfig: GenerationConfig(responseModalities: [ResponseModalities.image]),
);
// Prepare an image for the model to edit
final image = await File('scones.jpg').readAsBytes();
final imagePart = InlineDataPart('image/jpeg', image);
// Provide an initial text prompt instructing the model to edit the image
final prompt = TextPart("Edit this image to make it look like a cartoon");
// Initialize the chat
final chat = model.startChat();
// To generate an initial response, send a user message with the image and text prompt
final response = await chat.sendMessage([
Content.multi([prompt,imagePart])
]);
// Inspect the returned image
if (response.inlineDataParts.isNotEmpty) {
final imageBytes = response.inlineDataParts[0].bytes;
// Process the image
} else {
// Handle the case where no images were generated
print('Error: No images were generated.');
}
// Follow up requests do not need to specify the image again
final followUpResponse = await chat.sendMessage([
Content.text("But make it old-school line drawing style")
]);
// Inspect the returned image
if (followUpResponse.inlineDataParts.isNotEmpty) {
final followUpImageBytes = response.inlineDataParts[0].bytes;
// Process the image
} else {
// Handle the case where no images were generated
print('Error: No images were generated.');
}
Unity
using Firebase;
using Firebase.AI;
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a Gemini model that supports image output.
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetGenerativeModel(
modelName: "gemini-3.1-flash-image",
// Configure the model to respond with images only.
generationConfig: new GenerationConfig(
responseModalities: new[] { ResponseModality.Image })
);
// Prepare an image for the model to edit
var imageFile = System.IO.File.ReadAllBytes(System.IO.Path.Combine(
UnityEngine.Application.streamingAssetsPath, "scones.jpg"));
var image = ModelContent.InlineData("image/jpeg", imageFile);
// Provide an initial text prompt instructing the model to edit the image
var prompt = ModelContent.Text("Edit this image to make it look like a cartoon.");
// Initialize the chat
var chat = model.StartChat();
// To generate an initial response, send a user message with the image and text prompt
var response = await chat.SendMessageAsync(new [] { prompt, image });
// Inspect the returned image
var imageParts = response.Candidates.First().Content.Parts
.OfType<ModelContent.InlineDataPart>()
.Where(part => part.MimeType == "image/png");
// Load the image into a Unity Texture2D object
UnityEngine.Texture2D texture2D = new(2, 2);
if (texture2D.LoadImage(imageParts.First().Data.ToArray())) {
// Do something with the image
}
// Follow up requests do not need to specify the image again
var followUpResponse = await chat.SendMessageAsync("But make it old-school line drawing style");
// Inspect the returned image
var followUpImageParts = followUpResponse.Candidates.First().Content.Parts
.OfType<ModelContent.InlineDataPart>()
.Where(part => part.MimeType == "image/png");
// Load the image into a Unity Texture2D object
UnityEngine.Texture2D followUpTexture2D = new(2, 2);
if (followUpTexture2D.LoadImage(followUpImageParts.First().Data.ToArray())) {
// Do something with the image
}
ارائه تصاویر مرجع
Gemini مدلهای تصویر به شما امکان میدهند تصاویر مرجع را در پیاموارهتان ارائه دهید. این تصاویر میتواند شامل موارد زیر باشد:
Gemini 3.x Pro Image (
gemini-3-pro-image، با نام مستعار «Nano Banana Pro»)- حداکثر ۶ تصویر از اشیای با وفاداری بالا برای گنجاندن در تصویر نهایی
- حداکثر ۵ تصویر از شخصیتها برای حفظ یکپارچگی شخصیت
- حداکثر ۳ تصویر برای استفاده بهعنوان مرجع سبک
Gemini 3.x Flash Image (
gemini-3.1-flash-image، با نام مستعار «Nano Banana 2»):- حداکثر ۱۰ تصویر از اشیای با وفاداری بالا برای گنجاندن در تصویر نهایی
- حداکثر ۴ تصویر از شخصیتها برای حفظ یکپارچگی شخصیت
Gemini 3.x Flash‑Lite Image (
gemini-3.1-flash-lite-image، با نام مستعار «Nano Banana 2 Lite»):- حداکثر ۱۰ تصویر از اشیای با وفاداری بالا برای گنجاندن در تصویر نهایی
- حداکثر ۴ تصویر از شخصیتها برای حفظ یکپارچگی شخصیت
Gemini 2.5 Flash Image (
gemini-2.5-flash-image، با نام مستعار «نانو بنانا»):- حداکثر ۳ تصویر
پیکربندی تولید تصویر
بهطور پیشفرض، Gemini مدلهای تصویر، تصاویر مربعی
(نسبت ابعادی ۱:۱) با وضوح ۱۰۲۴x۱۰۲۴ تولید میکنند. میتوانید برونداد تصاویر تولیدشده را بااستفاده از دارایی imageConfig در generationConfig سفارشیسازی کنید.
برای مثال، میتوانید تصویر برونداد را بااستفاده از نسبت ابعادی و شمارش تصویر (مثل نسبت ابعادی ۱۶:۹ و وضوح ۲K که منجر به تصویر ۲۷۵۲x۱۵۳۶ میشود) پیکربندی کنید، به این صورت:
Swift
// ...
// Specify aspect ratio and image size (both optional) in an image config.
let imageConfig = ImageConfig(aspectRatio: .landscape16x9, imageSize: .size2K)
let generationConfig = GenerationConfig(
// Configure the model to respond with text (optional) and images (required).
// Include the text modality only if you want interleaved text and images in the response.
responseModalities: [.text, .image],
imageConfig: imageConfig
)
// Make sure you initialize your chosen Gemini API backend service
let model = FirebaseAI.firebaseAI().generativeModel(
modelName: "gemini-3.1-flash-image",
generationConfig: generationConfig
)
// ...
Kotlin
// ...
val config = generationConfig {
// Configure the model to respond with text (optional) and images (required).
// Include the text modality only if you want interleaved text and images in the response.
responseModalities = listOf(ResponseModality.TEXT, ResponseModality.IMAGE)
// Specify aspect ratio and image size (both optional) in an image config.
imageConfig = imageConfig {
aspectRatio = AspectRatio.LANDSCAPE_16x9
imageSize = ImageSize.SIZE_2K
}
}
// Make sure you initialize your chosen Gemini API backend service
val model = Firebase.ai.generativeModel(
modelName = "gemini-3.1-flash-image",
generationConfig = config
)
// ...
Java
// ...
GenerationConfig config = new GenerationConfig.Builder()
// Configure the model to respond with text (optional) and images (required).
// Include the text modality only if you want interleaved text and images in the response.
.setResponseModalities(Arrays.asList(ResponseModality.TEXT, ResponseModality.IMAGE))
// Specify aspect ratio and image size (both optional) in an image config.
.setImageConfig(
ImageConfig.builder()
.setAspectRatio(AspectRatio.LANDSCAPE_16x9)
.setImageSize(ImageSize.SIZE_2K)
.build()
)
.build();
// Make sure you initialize your chosen Gemini API backend service
GenerativeModel model = FirebaseAI.getInstance().generativeModel(
"gemini-3.1-flash-image",
config
);
// ...
Web
import {
getGenerativeModel,
ResponseModality,
ImageConfigAspectRatio,
ImageConfigImageSize
} from "firebase/ai";
// ...
const generationConfig = {
// Configure the model to respond with text (optional) and images (required).
// Include the text modality only if you want interleaved text and images in the response.
responseModalities: [ResponseModality.TEXT, ResponseModality.IMAGE],
// Specify aspect ratio and image size (both optional) in an image config.
imageConfig: {
aspectRatio: ImageConfigAspectRatio.LANDSCAPE_16x9,
imageSize: ImageConfigImageSize.SIZE_2K
}
};
// Make sure you initialize your chosen Gemini API backend service
const model = getGenerativeModel(ai, {
model: "gemini-3.1-flash-image",
generationConfig
});
// ...
Dart
// ...
final generationConfig = GenerationConfig(
// Configure the model to respond with text (optional) and images (required).
// Include the text modality only if you want interleaved text and images in the response.
responseModalities: [ResponseModalities.text, ResponseModalities.image],
// Specify aspect ratio and image size (both optional) in an image config.
imageConfig: ImageConfig(
aspectRatio: ImageAspectRatio.landscape16x9,
imageSize: ImageSize.size2K,
),
);
// Make sure you initialize your chosen Gemini API backend service
final model = FirebaseAI.instance.generativeModel(
model: 'gemini-3.1-flash-image,
generationConfig: generationConfig,
);
// ...
Unity
// ...
var generationConfig = new GenerationConfig(
// Configure the model to respond with text (optional) and images (required).
// Include the text modality only if you want interleaved text and images in the response.
responseModalities: new[] { ResponseModality.Text, ResponseModality.Image },
// Specify aspect ratio and image size (both optional) in an image config.
imageConfig: new ImageConfig(
aspectRatio: ImageConfig.AspectRatio.Landscape16x9,
imageSize: ImageConfig.ImageSize.Size2K)
);
// Make sure you initialize your chosen Gemini API backend service.
var model = FirebaseAI.GetInstance().GetGenerativeModel(
modelName: "gemini-3.1-flash-image",
generationConfig: generationConfig
);
// ...
نسبتهای ابعادی پشتیبانیشده
همه مدلهای تصویر Gemini از نسبتهای ابعادی زیر پشتیبانی میکنند:
پیشفرض: 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
اندازههای پشتیبانیشده تصویر (وضوح)
اندازههای تصویر پشتیبانیشده (وضوح) به مدلی که استفاده میکنید بستگی دارد.
| Gemini مدل تصویر | اندازههای پشتیبانیشده (وضوح) |
|---|---|
Gemini 3.x Pro Imagegemini-3-pro-image("Nano Banana Pro") |
پیشفرض: 1K (۱۰۲۴)1K (۱۰۲۴)، 2K (۲۰۴۸)، 4K (۴۰۹۶)
|
Gemini 3.x Flash Imagegemini-3.1-flash-image("Nano Banana 2") |
پیشفرض: 1K (۱۰۲۴)512، 1K (۱۰۲۴)، 2K (۲۰۴۸)، 4K (۴۰۹۶)
|
Gemini 3.x Flash‑Lite Imagegemini-3.1-flash-lite-image(«Nano Banana 2 Lite») |
پیشفرض: 1K (۱۰۲۴)512 (فقط Gemini Developer API)، 1K (۱۰۲۴)
|
Gemini 2.5 Flash Imagegemini-2.5-flash-image(«نانو موز») |
در 1K ثابت شد (۱۰۲۴)
|
باید از پسوند K حروف بزرگ (یعنی 1K، 2K، 4K) استفاده کنید.
مقدار 512 از پسوند K استفاده نمیکند.
پسوند k با حروف کوچک (برای مثال، 1k) رد خواهد شد.
ویژگیهای پشتیبانیشده
ویژگیهای پشتیبانیشده، مانند روشها، ابزارها، ورودی، و زبانها در زیر آمده است.
برای اطلاع از نسبتهای ابعادی و وضوحهای پشتیبانیشده برای هر مدل، به پیکربندی تولید تصویر در بخشهای قبلی این راهنما مراجعه کنید.
روشهای پشتیبانیشده
«روشهای» زیر برای مدلهای تصویر Gemini پشتیبانی میشوند. این «روشها» بهطور صریح در درخواستهای شما تنظیم نشدهاند. اینها بیشتر شبیه الگوهای توصیهشده برای موارد استفاده رایج هستند. هر روش در این فهرست یک پیامواره نمونه دارد و در بخشهای قبلی این راهنما یک نمونه کد دارد.
نوشتار تصویر(ها) (نوشتار-فقط به تصویر)
- تصویری از برج ایفل با آتشبازی در پسزمینه تولید کن.
نوشتار تصویر(ها) (پرداز نوشتار درون تصویر)
- عکس سینمایی از ساختمان بزرگی با این نوشتار غولپیکر بساز که روی نمای جلویی ساختمان تصویرسازی شده است.
نوشتار تصویر(ها) و نوشتار (درهمآمیخته)
دستور پخت مصوری برای پائلا تولید کن. همزمان با تولید دستور پخت، تصاویر را در کنار نوشتار ایجاد کنید.
داستانی درباره یک سگ بهسبک پویانمایی کارتونی سهبعدی تولید کن. برای هر صحنه، تصویری تولید کنید.
تصویر(ها) و نوشتار تصویر(ها) و نوشتار (درهمآمیخته)
- [تصویر اتاقی مبله] + چه رنگهای دیگری برای مبل در فضای من مناسب است؟ میتوانی تصویر را بهروز کنی؟
ویرایش تصویر (نوشتار و تصویر به تصویر)
[تصویر کیک اسکان] + این تصویر را ویرایش کن تا شبیه کارتون شود
[تصویر گربه] + [تصویر بالش] + یک گلدوزی ضربدری از گربهام روی این بالش بساز.
ویرایش چندنوبتی تصویر (گپ)
- [تصویر خودرو آبی] + این خودرو را به خودروی روباز تبدیل کن.، سپس اکنون رنگ آن را به زرد تغییر بده.
ابزارهای پشتیبانیشده
پشتیبانی از
زمینهسازی با
Gemini 3.x Pro Image (
gemini-3-pro-image، با نام مستعار «Nano Banana Pro»)Gemini 3.x Flash Image (
gemini-3.1-flash-image، با نام مستعار «Nano Banana 2»)
سایر قابلیتهای پشتیبانیشده
ورودی چندحالته پشتیبانیشده:
ورودی تصویر: همه مدلهای تصویر Gemini.
ورودی ویدیو:
- Gemini 3.x Flash Image
(
gemini-3.1-flash-image، با نام مستعار «Nano Banana 2») - Gemini 3.x Flash‑Lite Image
(
gemini-3.1-flash-lite-image، با نام مستعار «Nano Banana 2 Lite»)
- Gemini 3.x Flash Image
(
ورودی صوتی: هیچکدام از مدلهای Gemini «تصویر».
همه مدلهای تصویر Gemini از موارد زیر پشتیبانی میکنند:
- درحال تولید تصاویر PNG.
- تولید و ویرایش تصاویر افراد.
- استفاده از فیلترهای ایمنی که تجربه کاربری انعطافپذیر و کمتر محدودکنندهای ارائه میدهند.
پشتیبانی از تولید برونداد ساختاریافته (مثل JSON):
- Gemini 3.x Pro Image
(
gemini-3-pro-image، با نام مستعار «Nano Banana Pro»)
- Gemini 3.x Pro Image
(
زبانهای پشتیبانیشده
درحالیکه مدلهای Gemini تصویر میتوانند پیاموارههای نوشتاری را به بسیاری از زبانها بپذیرند، زبانهای فهرستشده در این بخش بهترین عملکرد را به شما ارائه خواهند داد.
زبانهای پشتیبانیشده برای پیامواره نوشتاری:
- Gemini 3.x Image مدل:
ar-EG،de-DE،EN،es-MX،fr-FR،hi-IN،id-ID،it-IT،ja-JP،ko-KR،pt-BR،ru-RU،uk-UA،vi-VN،zh-CN - مدل Gemini 2.5 Flash Image:
EN،es-MX،ja-JP،zh-CN،hi-IN.
- Gemini 3.x Image مدل:
زبانهای پشتیبانیشده برای نوشتار درون تصویر تولیدشده:
- Gemini 3.x Image مدل: زبانهای یکسان با فهرست بالا
- مدل Gemini 2.5 Flash Image: فقط انگلیسی
برای استفاده از زبانی خاص در تصویر تولیدشده (حتی بدون کد زبان)، کافی است در پیاموارهتان از مدل بخواهید (برای نمونه، «این اطلاعات تصویری را به زبان اسپانیایی بهروز کن. هیچیک از عناصر دیگر تصویر را تغییر نده.»).
روالهای مطلوب
موارد زیر روالهای مطلوب برای مدلهای تصویر Gemini است.
هنگام تولید تصویر حاوی نوشتار، ابتدا نوشتار را تولید کنید و سپس تصویری با آن نوشتار تولید کنید.
تولید تصویر ممکن است همیشه فعال نشود. همچنین، تولید تصویر یا نوشتار ممکن است در این شرایط آنطور که انتظار میرود کار نکند:
مدل ممکن است فقط نوشتار تولید کند و تصویری تولید نکند (بهویژه اگر پیامواره مبهم باشد). اگر این اتفاق بیفتد،
FinishReasonNO_IMAGEاست.
بهطور صریح درخواست برونداد تصویر کنید. برای مثال، «تصویری تولید کن»، «همزمان با پیش رفتن، تصویر ارائه کن»، «تصویر را بهروز کن».این مدل ممکن است تولید را در نیمه راه متوقف کند.
دوباره امتحان کنید یا پیامواره دیگری را امتحان کنید.این مدل ممکن است نوشتار را بهصورت تصویر تولید کند.
بهطور صریح درخواست برونداد نوشتاری کنید. برای مثال، «تولید روایت نوشتار همراه با تصویرسازی».اگر پیاموارهای بهطور بالقوه ناامن باشد، ممکن است مدل درخواست را پردازش نکند و درعوض پاسخی برگرداند که نشان میدهد نمیتواند تصاویر ناامن ایجاد کند. اگر این اتفاق بیفتد،
FinishReasonSTOPاست.