Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
L'aperçu Gemini 2.5 Flash Image est compatible avec plusieurs types de retouche d'image.
Édition d'images
La version Preview publique de Gemini 2.5 Flash Image pour la génération d'images (gemini-2.5-flash-image-preview) permet de modifier les images en plus de les générer. Avec cette version Preview publique, l'image Gemini 2.5 Flash permet de mieux modifier les images et d'effectuer des modifications en plusieurs étapes. Elle contient également des filtres de sécurité mis à jour qui offrent une expérience utilisateur plus flexible et moins restrictive.
Il est compatible avec les modalités et les fonctionnalités suivantes :
Retouche d'images (texte vers image et image vers image)
Exemple de requête : "Modifie cette image pour qu'elle ressemble à un dessin animé"
Exemple de requête : [image de chat] + [image d'oreiller] + "Crée un point de croix de mon chat sur cet oreiller."
Modification d'images multitour (chat)
Exemples de requêtes : [importe une image d'une voiture bleue]. "Transforme cette voiture en cabriolet." "Maintenant, change la couleur en jaune."
"Ajoute un spoiler."
Cliquez sur Changer de modèle, puis sélectionnez gemini-2.5-flash-image-preview dans le menu.
Dans le panneau Sorties, sélectionnez Image et texte dans le menu déroulant.
Cliquez sur Insérer un média (add_photo_alternate), sélectionnez une source dans le menu, puis suivez les instructions de la boîte de dialogue.
Dans la zone de texte Écrivez une requête, décrivez les modifications que vous souhaitez apporter à l'image.
Cliquez sur le bouton Requête (send).
Gemini générera une version modifiée de l'image fournie en fonction de votre description. Ce processus devrait prendre quelques secondes, mais peut être relativement plus lent en fonction de la capacité.
Définissez les variables d'environnement pour utiliser le SDK Gen AI avec Vertex AI :
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values# with appropriate values for your project.exportGOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECTexportGOOGLE_CLOUD_LOCATION=globalexportGOOGLE_GENAI_USE_VERTEXAI=True
fromgoogleimportgenaifromgoogle.genai.typesimportGenerateContentConfig,ModalityfromPILimportImagefromioimportBytesIOclient=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]),)forpartinresponse.candidates[0].content.parts:ifpart.text:print(part.text)elifpart.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
Exécutez la commande suivante dans le terminal pour créer ou écraser ce fichier dans le répertoire actuel :
curl-XPOST\-H"Authorization: Bearer $(gcloudauthprint-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 génère une image en fonction de votre description. Ce processus devrait prendre quelques secondes, mais peut être relativement plus lent en fonction de la capacité.
Modification d'images multitour
Gemini 2.5 Flash Image Preview permet également d'améliorer la retouche multitour. Vous pouvez ainsi répondre au modèle en lui demandant d'apporter des modifications après avoir reçu une image retouchée.
Vous pourrez ainsi continuer à modifier l'image de manière conversationnelle.
Notez qu'il est recommandé de limiter la taille totale du fichier de requête à 50 Mo maximum.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/10 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/10 (UTC)."],[],[],null,["# Edit images with Gemini\n\n| **Preview**\n|\n|\n| This product or feature is a Generative AI Preview offering, subject to\n| the \"Pre-GA Offerings Terms\" of the\n| [Google Cloud Service Specific Terms](/terms/service-terms),\n| as well as the\n| [Additional Terms for Generative AI Preview Products](/trustedtester/aitos). For this\n| Generative AI Preview offering, Customers may elect to use it for\n| production or commercial purposes, or disclose Generated Output to\n| third-parties, and may process personal data as outlined in the\n| [Cloud Data Processing\n| Addendum](/terms/data-processing-addendum),\n| subject to the obligations and restrictions described in the agreement\n| under which you access Google Cloud. Pre-GA products are available \"as is\"\n| and might have limited support. For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\n\u003cbr /\u003e\n\nGemini 2.5 Flash Image Preview supports multiple types of image editing.\n| **Note:** Image editing and multi-turn image editing are only supported in `gemini-2.5-flash-image-preview`, not `gemini-2.5-flash`.\n\nImage editing\n-------------\n\n| To see an example of image editing with Gemini,\n| run the \"Gemini 2.5 Flash Image Generation in Vertex AI\" notebook in one of the following\n| environments:\n|\n| [Open in Colab](https://colab.research.google.com/github/GoogleCloudPlatform/generative-ai/blob/main/gemini/getting-started/intro_gemini_2_5_image_gen.ipynb)\n|\n|\n| \\|\n|\n| [Open in Colab Enterprise](https://console.cloud.google.com/vertex-ai/colab/import/https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fgenerative-ai%2Fmain%2Fgemini%2Fgetting-started%2Fintro_gemini_2_5_image_gen.ipynb)\n|\n|\n| \\|\n|\n| [Open\n| in Vertex AI Workbench](https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fgenerative-ai%2Fmain%2Fgemini%2Fgetting-started%2Fintro_gemini_2_5_image_gen.ipynb)\n|\n|\n| \\|\n|\n| [View on GitHub](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/getting-started/intro_gemini_2_5_image_gen.ipynb)\n\nGemini 2.5 Flash Image's public preview for image generation\n(`gemini-2.5-flash-image-preview`) supports the ability to edit\nimages in addition generating them. With this public preview release,\nGemini 2.5 Flash Image supports improved editing of images and\nmulti-turn editing and contains updated safety filters that provide a more\nflexible and less restrictive user experience.\n\nIt supports the following modalities and capabilities:\n\n- Image editing (text and image to image)\n\n - **Example prompt:** \"Edit this image to make it look like a cartoon\"\n - **Example prompt:** \\[image of a cat\\] + \\[image of a pillow\\] + \"Create a cross stitch of my cat on this pillow.\"\n- Multi-turn image editing (chat)\n\n - **Example prompts:** \\[upload an image of a blue car.\\] \"Turn this car into a convertible.\" \"Now change the color to yellow.\" \"Add a spoiler.\"\n\nEdit an image\n-------------\n\n### Console\n\nTo edit images:\n\n1. Open [**Vertex AI Studio \\\u003e Create prompt**](https://console.cloud.google.com/vertex-ai/studio/multimodal).\n2. Click **Switch model** and select **`gemini-2.5-flash-image-preview`** from the menu.\n3. In the **Outputs** panel, select **Image and text** from the drop-down menu.\n4. Click **Insert media** (add_photo_alternate) and select a source from the menu, then follow the dialog's instructions.\n5. Write what edits you want to make to the image in the **Write a prompt** text area.\n6. Click the **Prompt** (send) button.\n\n\nGemini will generate an edited version of the provided image based on\nyour description. This process should take a few seconds, but may be\ncomparatively slower depending on capacity.\n\n### Python\n\n#### Install\n\n```\npip install --upgrade google-genai\n```\n\n\nTo learn more, see the\n[SDK reference documentation](https://googleapis.github.io/python-genai/).\n\n\nSet environment variables to use the Gen AI SDK with Vertex AI:\n\n```bash\n# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values\n# with appropriate values for your project.\nexport GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT\nexport GOOGLE_CLOUD_LOCATION=global\nexport GOOGLE_GENAI_USE_VERTEXAI=True\n```\n\n\u003cbr /\u003e\n\n from google import genai\n from google.genai.types import GenerateContentConfig, Modality\n from PIL import Image\n from io import BytesIO\n\n client = genai.Client()\n\n # Using an image of Eiffel tower, with fireworks in the background.\n image = Image.open(\"test_resources/example-image-eiffel-tower.png\")\n\n response = client.models.generate_content(\n model=\"gemini-2.5-flash-image-preview\",\n contents=[image, \"Edit this image to make it look like a cartoon.\"],\n config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]),\n )\n for part in response.candidates[0].content.parts:\n if part.text:\n print(part.text)\n elif part.inline_data:\n image = Image.open(BytesIO((part.inline_data.data)))\n image.save(\"output_folder/bw-example-image.png\")\n # Example response:\n # Here's the cartoon-style edit of the image:\n # Cartoon-style edit:\n # - Simplified the Eiffel Tower with bolder lines and slightly exaggerated proportions.\n # - Brightened and saturated the colors of the sky, fireworks, and foliage for a more vibrant, cartoonish look.\n # ....\n\n### REST\n\n\nRun the following command in the terminal to create or overwrite this file in\nthe current directory: \n\n curl -X POST \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Content-Type: application/json\" \\\n https://${API_ENDPOINT}:generateContent \\\n -d '{\n \"contents\": {\n \"role\": \"USER\",\n \"parts\": [\n {\"file\u003c_da\u003eta\":\u003c {\n \u003e \"mime_type\": \"image/jpg\",\n \"file_uri\": \"varFILE_NAME/var\"\n }\n },\n {\"text\": \"Convert this photo to black and white, in a cartoonish style.\"},\n ]\n\n },\n \"generation_config\": {\n \"response_modalities\": [\"TEXT\", \"IMAGE\"]\u003e,\n },\n \u003e \"safetySettings\": {\n \"method\": \"PROBABILITY\",\n \"category\": \"HARM_CATEGORY_DANGEROUS_CONTENT\",\n \"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"\n },\n }' 2/dev/null response.json\n\n| **Note:** You **must** include `responseModalities: [\"TEXT\", \"IMAGE\"]` in your configuration. Image-only output is not supported with these models.\n\n\nGemini will generate an image based on your description. This\nprocess should take a few seconds, but may be comparatively slower depending on\ncapacity.\n\n\u003cbr /\u003e\n\nMulti-turn image editing\n------------------------\n\nGemini 2.5 Flash Image Preview also supports improved multi-turn editing, allowing\nyou to respond to the model with changes after receiving an edited image response.\nThis will allow you to continue to make edits to the image conversationally.\n\nNote that is recommended to limit the entire request file size to 50MB maximum.\n\nTo test out multi-turn image editing, try our\n[Gemini 2.5 Flash Image Preview notebook](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/getting-started/intro_gemini_2_5_image_gen.ipynb)."]]