Edit images with Gemini

Preview

This product or feature is a Generative AI Preview offering, subject to the "Pre-GA Offerings Terms" of the Google Cloud Service Specific Terms , as well as the Additional Terms for Generative AI Preview Products . For this Generative AI Preview offering, Customers may elect to use it for production or commercial purposes, or disclose Generated Output to third-parties, and may process personal data as outlined in the Cloud Data Processing Addendum , subject to the obligations and restrictions described in the agreement under which you access Google Cloud. Pre-GA products are available "as is" and might have limited support. For more information, see the launch stage descriptions .

Gemini 2.5 Flash Image Preview supports multiple types of image editing.

Image editing

Gemini 2.5 Flash Image's public preview for image generation ( gemini-2.5-flash-image-preview ) supports the ability to edit images in addition generating them. With this public preview release, Gemini 2.5 Flash Image supports improved editing of images and multi-turn editing and contains updated safety filters that provide a more flexible and less restrictive user experience.

It supports the following modalities and capabilities:

  • Image editing (text and image to image)

    • Example prompt:"Edit this image to make it look like a cartoon"
    • Example prompt:[image of a cat] + [image of a pillow] + "Create a cross stitch of my cat on this pillow."
  • Multi-turn image editing (chat)

    • Example prompts:[upload an image of a blue car.] "Turn this car into a convertible." "Now change the color to yellow." "Add a spoiler."

Edit an image

Console

To edit images:

  1. Open Vertex AI Studio > Create prompt .
  2. Click Switch model and select gemini-2.5-flash-image-preview from the menu.
  3. In the Outputs panel, select Image and text from the drop-down menu.
  4. Click Insert media ( ) and select a source from the menu, then follow the dialog's instructions.
  5. Write what edits you want to make to the image in the Write a prompt text area.
  6. Click the Prompt ( ) button.

Gemini will generate an edited version of the provided image based on your description. This process should take a few seconds, but may be comparatively slower depending on capacity.

Python

Install

pip install --upgrade google-genai

To learn more, see the SDK reference documentation .

Set environment variables to use the Gen AI SDK with Vertex AI:

 # Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values 
 # with appropriate values for your project. 
 export 
  
 GOOGLE_CLOUD_PROJECT 
 = 
 GOOGLE_CLOUD_PROJECT 
 export 
  
 GOOGLE_CLOUD_LOCATION 
 = 
 global 
 export 
  
 GOOGLE_GENAI_USE_VERTEXAI 
 = 
True
  from 
  
 google 
  
 import 
 genai 
 from 
  
 google.genai.types 
  
 import 
 GenerateContentConfig 
 , 
 Modality 
 from 
  
 PIL 
  
 import 
 Image 
 from 
  
 io 
  
 import 
 BytesIO 
 client 
 = 
 genai 
 . 
 Client 
 () 
 # Using an image of Eiffel tower, with fireworks in the background. 
 image 
 = 
 Image 
 . 
 open 
 ( 
 "test_resources/example-image-eiffel-tower.png" 
 ) 
 response 
 = 
 client 
 . 
 models 
 . 
 generate_content 
 ( 
 model 
 = 
 "gemini-2.5-flash-image-preview" 
 , 
 contents 
 = 
 [ 
 image 
 , 
 "Edit this image to make it look like a cartoon." 
 ], 
 config 
 = 
 GenerateContentConfig 
 ( 
 response_modalities 
 = 
 [ 
 Modality 
 . 
 TEXT 
 , 
 Modality 
 . 
 IMAGE 
 ]), 
 ) 
 for 
 part 
 in 
 response 
 . 
 candidates 
 [ 
 0 
 ] 
 . 
 content 
 . 
 parts 
 : 
 if 
 part 
 . 
 text 
 : 
 print 
 ( 
 part 
 . 
 text 
 ) 
 elif 
 part 
 . 
 inline_data 
 : 
 image 
 = 
 Image 
 . 
 open 
 ( 
 BytesIO 
 (( 
 part 
 . 
 inline_data 
 . 
 data 
 ))) 
 image 
 . 
 save 
 ( 
 "output_folder/bw-example-image.png" 
 ) 
 # Example response: 
 #  Here's the cartoon-style edit of the image: 
 #  Cartoon-style edit: 
 #  - Simplified the Eiffel Tower with bolder lines and slightly exaggerated proportions. 
 #  - Brightened and saturated the colors of the sky, fireworks, and foliage for a more vibrant, cartoonish look. 
 #  .... 
 

REST

Run the following command in the terminal to create or overwrite this file in the current directory:

 curl  
-X  
POST  
 \ 
  
-H  
 "Authorization: Bearer 
 $( 
gcloud  
auth  
print-access-token ) 
 " 
  
 \ 
  
-H  
 "Content-Type: application/json" 
  
 \ 
  
https:// ${ 
 API_ENDPOINT 
 } 
:generateContent  
 \ 
  
-d  
 '{ 
 "contents": { 
 "role": "USER", 
 "parts": [ 
 {"file_data": { 
 "mime_type": "image/jpg", 
 "file_uri": "<var>FILE_NAME</var>" 
 } 
 }, 
 {"text": "Convert this photo to black and white, in a cartoonish style."}, 
 ] 
 }, 
 "generation_config": { 
 "response_modalities": ["TEXT", "IMAGE"], 
 }, 
 "safetySettings": { 
 "method": "PROBABILITY", 
 "category": "HARM_CATEGORY_DANGEROUS_CONTENT", 
 "threshold": "BLOCK_MEDIUM_AND_ABOVE" 
 }, 
 }' 
  
 2 
>/dev/null  
>response.json 

Gemini will generate an image based on your description. This process should take a few seconds, but may be comparatively slower depending on capacity.

Multi-turn image editing

Gemini 2.5 Flash Image Preview also supports improved multi-turn editing, allowing you to respond to the model with changes after receiving an edited image response. This will allow you to continue to make edits to the image conversationally.

Note that is recommended to limit the entire request file size to 50MB maximum.

To test out multi-turn image editing, try our Gemini 2.5 Flash Image Preview notebook .

Create a Mobile Website
View Site in Mobile | Classic
Share by: