Imagen에서 Gemini 이미지 모델 ('Nano Banana')로 이전


모든 Imagen 모델은 지원 중단되었으며 2026년 8월 17일에 종료될 예정입니다. 이 지원 중단 및 종료는 Google 전반에 적용되며 Gemini Developer API 및 Agent Platform Gemini API (formerly Vertex AI) 모두에 적용됩니다.

서비스 중단을 방지하려면 이 종료일 전에 이 가이드에 설명된 대로 Imagen 모델 사용에서 Gemini 3.x Image 모델('Nano Banana' 모델) 사용으로 앱을 마이그레이션해야 합니다.

이 지원 중단 및 종료와 관련된 긴급한 문제가 있는 경우 Firebase 지원팀에 문의하세요.

대체 Gemini 이미지 모델

다음 표를 검토하여 앱의 대체 Gemini 3.x Image 모델을 선택하세요.

모델 Imagen개 Gemini 3.x Image 모델 ('Nano Banana')
imagen-4.0-fast-generate-001 gemini-3.1-flash-image (사고 수준 MINIMAL)
imagen-4.0-generate-001 gemini-3.1-flash-image (사고 수준 HIGH)
imagen-4.0-ultra-generate-001 gemini-3-pro-image
imagen-3.0-capability-001 gemini-3.1-flash-image

앱 마이그레이션

이 섹션에서는 Imagen 모델에서 Gemini 이미지 모델로 이전하는 전후의 예를 보여줍니다.

텍스트에서 이미지 생성

Gemini API 제공업체를 클릭하여 이 페이지에서 제공업체별 콘텐츠와 코드를 확인합니다.

텍스트에서 이미지를 생성하려면 다음 변경사항을 적용하여 앱을 이전하세요.

  • 적절한 대체 Gemini 이미지 모델(예: gemini-3.1-flash-image)을 사용합니다.

  • ImagenModel 인스턴스 대신 GenerativeModel 인스턴스를 만듭니다.

  • Gemini 이미지 모델을 수용하도록 모델 구성 옵션을 업데이트합니다.

    • 이 구성의 일부로 응답 모달리티를 IMAGE로 설정합니다.
      Gemini 이미지 모델은 이미지 및 텍스트를 모두 반환하도록 구성할 수 있습니다.

Swift

이전


import FirebaseAILogic

// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())

// Create an `ImagenModel` instance with a model that supports your use case.
let model = ai.imagenModel(modelName: "IMAGEN_MODEL_NAME")

// Provide an image generation prompt.
let prompt = "An astronaut riding a horse"

// To generate an image, call `generateImages` with the text prompt.
let response = try await model.generateImages(prompt: prompt)

// Handle the generated image.
guard let image = response.images.first else {
  fatalError("No image in the response.")
}
let uiImage = UIImage(data: image.data)

이후


import FirebaseAILogic

// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())

// Create a `GenerativeModel` instance with a Gemini model that supports image output.
let model = ai.generativeModel(
  modelName: "GEMINI_IMAGE_MODEL_NAME",
  generationConfig: GenerationConfig(
    responseModalities: [.image],
    imageConfig: ImageConfig(aspectRatio: .landscape4x3)
  )
)

// Provide an image generation prompt.
let prompt = "An astronaut riding a horse"

// To generate an image, call `generateContent` with the text prompt.
let response = try await model.generateContent(prompt)

// Handle the case where no images were generated.
guard let inlineDataPart = response.inlineDataParts.first else {
  fatalError("No image in the response.")
}

// Process the image.
guard let uiImage = UIImage(data: inlineDataPart.data) else {
  fatalError("Failed to convert data to UIImage.")
}

Kotlin

이전


// Initialize the Gemini Developer API backend service.
val ai = Firebase.ai(backend = GenerativeBackend.googleAI())

// Create an `ImagenModel` instance with an Imagen model that supports your use case.
val model = ai.imagenModel("IMAGEN_MODEL_NAME")

// Provide an image generation prompt.
val prompt = "An astronaut riding a horse"

// To generate an image, call `generateImages` with the text prompt.
val imageResponse = model.generateImages(prompt)

// Handle the generated image.
val image = imageResponse.images.first()

val bitmapImage = image.asBitmap()

이후


// Initialize the Gemini Developer API backend service.
val ai = Firebase.ai(backend = GenerativeBackend.googleAI())

// Create a `GenerativeModel` instance with a Gemini model that supports image output.
val model = ai.generativeModel(
    modelName = "GEMINI_IMAGE_MODEL_NAME",
    generationConfig = generationConfig {
      responseModalities = listOf(ResponseModality.IMAGE),
      imageConfig = imageConfig {
        aspectRatio = AspectRatio.LANDSCAPE_4x3
      }
    }
)

// Provide an image generation prompt.
val prompt = "An astronaut riding a horse"

// To generate an image, call `generateContent` with the text prompt.
val imageResponse = model.generateContent(prompt)

if (imageResponse.finishReason == FinishReason.NO_IMAGE) {
  // Handle the case where no images were generated.
} else {
  // Handle the generated image.
  val bitmapImage = imageResponse.candidates.first().content.parts.filterIsInstance().firstOrNull()?.image
}

Java

이전


// Initialize the Gemini Developer API backend service.
// Create an `ImagenModel` instance with an Imagen model that supports your use case.
ImagenModel imagenModel = FirebaseAI.getInstance(GenerativeBackend.googleAI())
        .imagenModel(
                /* modelName */ "IMAGEN_MODEL_NAME");

ImagenModelFutures model = ImagenModelFutures.from(imagenModel);

// Provide an image generation prompt.
String prompt = "An astronaut riding a horse";

// To generate an image, call `generateImages` with the text prompt.
Futures.addCallback(model.generateImages(prompt), new FutureCallback<ImagenGenerationResponse>() {
    @Override
    public void onSuccess(ImagenGenerationResponse result) {
        if (result.getImages().isEmpty()) {
            Log.d("TAG", "No images generated");
        }
        Bitmap bitmap = result.getImages().get(0).asBitmap();
        // Use the bitmap to display the image in your UI.
    }

    @Override
    public void onFailure(Throwable t) {
        // ...
    }
}, Executors.newSingleThreadExecutor());

이후


// 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_IMAGE_MODEL_NAME",
    new GenerationConfig.Builder()
        .setResponseModalities(Arrays.asList(ResponseModality.IMAGE))
        .setImageConfig(new ImageConfig(AspectRatio.LANDSCAPE_4x3, null))
        .build()
);

GenerativeModelFutures model = GenerativeModelFutures.from(ai);

// Provide a text prompt instructing the model to generate an image.
Content prompt = new Content.Builder()
        .addText("An astronaut riding a horse")
        .build();

// To generate an image, call `generateContent` with the text input.
Executor executor = Executors.newSingleThreadExecutor();
ListenableFuture response = model.generateContent(prompt);
Futures.addCallback(response, new FutureCallback() {
    @Override
    public void onSuccess(GenerateContentResponse result) {
        if (result.finishReason == FinishReason.NO_IMAGE) {
            // handle the case where no images were generated
            return;
        }
        // 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, getImagenModel, GoogleAIBackend } from "firebase/ai";

// TODO(developer): Replace the following with your app's Firebase configuration
const firebaseConfig = {
  // ...
};

// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);

// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Create an `ImagenModel` instance with an Imagen model that supports your use case.
const model = getImagenModel(ai, { model: "IMAGEN_MODEL_NAME" });

// Provide an image generation prompt.
const prompt = "An astronaut riding a horse.";

// To generate an image, call `generateImages` with the text prompt.
const response = await model.generateImages(prompt)

// If fewer images were generated than were requested,
// then `filteredReason` will describe the reason they were filtered out.
if (response.filteredReason) {
  console.log(response.filteredReason);
}

if (response.images.length == 0) {
  throw new Error("No images in the response.")
}

const image = response.images[0];

이후


import { initializeApp } from "firebase/app";
import {
  getAI,
  getGenerativeModel,
  GoogleAIBackend,
  ResponseModality,
  ImageConfigAspectRatio,
  FinishReason
} from "firebase/ai";

// TODO(developer): Replace the following with your app's Firebase configuration
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_IMAGE_MODEL_NAME",
  generationConfig: {
    responseModalities: [ResponseModality.IMAGE],
    imageConfig: {
      aspectRatio: ImageConfigAspectRatio.LANDSCAPE_4x3
    }
  },
});

// Provide an image generation prompt.
const prompt = "An astronaut riding a horse.";

// To generate an image, call `generateContent` with the text prompt.
const result = await model.generateContent(prompt);

// Handle the generated image.
try {
  const response = result.response;
  if (response.candidates?.[0].finishReason == FinishReason.NO_IMAGE) {
    // Handle the case where no images were generated.
  }
  const inlineDataParts = response.inlineDataParts();
  if (inlineDataParts?.[0]) {
    const image = inlineDataParts[0].inlineData;
    // Use this mimeType and base64 data to display the image using your preferred tooling.
    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';

// Initialize FirebaseApp
await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

// Initialize the Gemini Developer API backend service.
final ai = FirebaseAI.googleAI();

// Create an `ImagenModel` instance with an Imagen model that supports your use case.
final model = ai.imagenModel(model: 'IMAGEN_MODEL_NAME');

// Provide an image generation prompt.
const prompt = 'An astronaut riding a horse.';

// To generate an image, call `generateImages` with the text prompt.
final response = await model.generateImages(prompt);

if (response.images.isNotEmpty) {
  final image = response.images[0];
  // Process the image.
} else {
  // Handle the case where no images were generated.
  print('Error: No images were generated.');
}

이후


import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

// Initialize FirebaseApp
await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

// Initialize the Gemini Developer API backend service.
final ai = FirebaseAI.googleAI();

// Create a `GenerativeModel` instance with a Gemini model that supports image output.
final model = ai.generativeModel(
  model: 'GEMINI_IMAGE_MODEL_NAME',
  generationConfig: GenerationConfig(
    responseModalities: [ResponseModalities.image],
    imageConfig: ImageConfig(aspectRatio: ImageAspectRatio.landscape4x3)
  ),
);

// Provide a text prompt instructing the model to generate an image.
final prompt = [Content.text('An astronaut riding a horse.')];

// To generate an image, call `generateContent` with the text prompt.
final response = await model.generateContent(prompt);
if (response.inlineDataParts.isNotEmpty) {
  final imageBytes = response.inlineDataParts.first.bytes;
  // Process the image.
} else {
  // Handle the case where no images were generated.
  print('Error: No images were generated.');
}

Unity

이전


using Firebase.AI;

// Initialize the Gemini Developer API backend service
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());

// Create an `ImagenModel` instance with a model that supports your use case
var model = ai.GetImagenModel(modelName: "IMAGEN_MODEL_NAME");

// Provide an image generation prompt
var prompt = "An astronaut riding a horse";

// To generate an image, call `generateImages` with the text prompt
var response = await model.GenerateImagesAsync(prompt: prompt);

// Handle the generated image
if (response.Images.Count == 0) {
  throw new Exception("No image in the response.");
}
var image = response.Images[0].AsTexture2D();

이후


using Firebase;
using Firebase.AI;

// Initialize the Gemini Developer API backend service.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());

// Create a `GenerativeModel` instance with a Gemini model that supports image output.
var model = ai.GetGenerativeModel(
  modelName: "GEMINI_IMAGE_MODEL_NAME",
  generationConfig: new GenerationConfig(
    responseModalities: new[] { ResponseModality.Image },
    imageConfig: new ImageConfig(aspectRatio: ImageConfig.AspectRatio.Landscape4x3)
  )
);

// Provide an image generation prompt.
var prompt = "An astronaut riding a horse";

// To generate an image, call `GenerateContentAsync` with the text prompt.
var response = await model.GenerateContentAsync(prompt);

if (response.Candidates.First().FinishReason == FinishReason.NoImage) {
  // Handle the case where no images were generated.
}

// 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.
  }
}

대체 구성 옵션

이 섹션에서는 모델의 대답을 제어하는 데 도움이 되는 다양한 모델 구성 옵션의 대체 옵션을 설명합니다.

안전 설정

ImagenSafetySettings을 사용하여 Imagen 모델의 안전 설정을 구성합니다. 하지만 Gemini 이미지 모델의 경우 SafetySetting을 사용하도록 이전해야 합니다.

모델 구성 매개변수

ImagenGenerationConfig으로 Imagen 모델을 구성합니다. 하지만 Gemini 이미지 모델의 경우 GenerationConfig 및 선택적으로 중첩된 ImageConfig을 사용하도록 마이그레이션해야 합니다(이는 2026년 5월 초 버전의 SDK부터 사용 가능).

GenerationConfig의 일부로 IMAGE의 응답 모달리티를 설정합니다 (이 가이드의 앞부분에 나오는 'after' 코드 샘플 참고). 원하는 경우 IMAGE 및 TEXT을 모두 반환하도록 Gemini 이미지 모델을 구성할 수 있습니다.

다음 표를 검토하여 Imagen에서 Gemini 이미지 모델로 모델 구성 매개변수를 이전하는 방법을 알아보세요.

모델 Imagen개 Gemini 3.x Image 모델 ('Nano Banana')
addWatermark

지원되지 않음

Gemini 이미지 모델은 항상 SynthID 워터마크가 포함된 AI 생성 이미지를 반환합니다.

aspectRatio

ImageConfig에서 aspectRatio 사용

코드 샘플 및 지원되는 값은 Gemini 이미지 모델 가이드의 이미지 생성 구성을 참고하세요.

imageFormat

지원되지 않음

Gemini 이미지 모델은 항상 생성된 이미지를 PNG 형식으로 반환합니다.

negativePrompt

지원되지 않음

부정 프롬프트는 기존 기능이며 imagen-3.0-generate-002 이후(또는 Imagen 4 모델)에는 지원되지 않습니다.

numberOfImages

지원되지 않음

Gemini 이미지 모델은 항상 생성된 이미지 하나를 반환합니다.
해결 방법으로 루프에서 생성을 실행하여 동일한 결과를 얻을 수 있습니다. 후보자 수는 대체로 사용할 수 없습니다.

personGeneration

지원되지 않음

기본적으로 Gemini 이미지 모델은 사람 이미지를 생성할 수 있습니다.