{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ijGzTHJJUCPY"
      },
      "outputs": [],
      "source": [
        "# Copyright 2025 Google LLC\n",
        "#\n",
        "# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "#     https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VEqbX8OhE8y9"
      },
      "source": [
        "# Imagen 4 Image Generation\n",
        "\n",
        "<table align=\"left\">\n",
        "  <td style=\"text-align: center\">\n",
        "    <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/generative-ai/blob/main/vision/getting-started/imagen4_image_generation.ipynb\">\n",
        "      <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Google Colaboratory logo\"><br> Run in Colab\n",
        "    </a>\n",
        "  </td>\n",
        "  <td style=\"text-align: center\">\n",
        "    <a href=\"https://console.cloud.google.com/vertex-ai/colab/import/https:%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fgenerative-ai%2Fmain%2Fvision%2Fgetting-started%2Fimagen4_image_generation.ipynb\">\n",
        "      <img width=\"32px\" src=\"https://lh3.googleusercontent.com/JmcxdQi-qOpctIvWKgPtrzZdJJK-J3sWE1RsfjZNwshCFgE_9fULcNpuXYTilIR2hjwN\" alt=\"Google Cloud Colab Enterprise logo\"><br> Run in Colab Enterprise\n",
        "    </a>\n",
        "  </td>\n",
        "  <td style=\"text-align: center\">\n",
        "    <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/generative-ai/main/vision/getting-started/imagen4_image_generation.ipynb\">\n",
        "      <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\"><br> Open in Vertex AI Workbench\n",
        "    </a>\n",
        "  </td>    \n",
        "  <td style=\"text-align: center\">\n",
        "    <a href=\"https://github.com/GoogleCloudPlatform/generative-ai/blob/main/vision/getting-started/imagen4_image_generation.ipynb\">\n",
        "      <img img width=\"32px\" src=\"https://raw.githubusercontent.com/primer/octicons/refs/heads/main/icons/mark-github-24.svg\" alt=\"GitHub logo\"><br> View on GitHub\n",
        "    </a>\n",
        "  </td>\n",
        "</table>\n",
        "\n",
        "<div style=\"clear: both;\"></div>\n",
        "\n",
        "<b>Share to:</b>\n",
        "\n",
        "<a href=\"https://www.linkedin.com/sharing/share-offsite/?url=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/vision/getting-started/imagen4_image_generation.ipynb\" target=\"_blank\">\n",
        "  <img width=\"20px\" src=\"https://upload.wikimedia.org/wikipedia/commons/8/81/LinkedIn_icon.svg\" alt=\"LinkedIn logo\">\n",
        "</a>\n",
        "\n",
        "<a href=\"https://bsky.app/intent/compose?text=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/vision/getting-started/imagen4_image_generation.ipynb\" target=\"_blank\">\n",
        "  <img width=\"20px\" src=\"https://upload.wikimedia.org/wikipedia/commons/7/7a/Bluesky_Logo.svg\" alt=\"Bluesky logo\">\n",
        "</a>\n",
        "\n",
        "<a href=\"https://twitter.com/intent/tweet?url=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/vision/getting-started/imagen4_image_generation.ipynb\" target=\"_blank\">\n",
        "  <img width=\"20px\" src=\"https://upload.wikimedia.org/wikipedia/commons/5/5a/X_icon_2.svg\" alt=\"X logo\">\n",
        "</a>\n",
        "\n",
        "<a href=\"https://reddit.com/submit?url=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/vision/getting-started/imagen4_image_generation.ipynb\" target=\"_blank\">\n",
        "  <img width=\"20px\" src=\"https://redditinc.com/hubfs/Reddit%20Inc/Brand/Reddit_Logo.png\" alt=\"Reddit logo\">\n",
        "</a>\n",
        "\n",
        "<a href=\"https://www.facebook.com/sharer/sharer.php?u=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/vision/getting-started/imagen4_image_generation.ipynb\" target=\"_blank\">\n",
        "  <img width=\"20px\" src=\"https://upload.wikimedia.org/wikipedia/commons/5/51/Facebook_f_logo_%282019%29.svg\" alt=\"Facebook logo\">\n",
        "</a>            \n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "G1KDmM_PBAXz"
      },
      "source": [
        "| Author |\n",
        "| --- |\n",
        "| [Katie Nguyen](https://github.com/katiemn) |"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CkHPv2myT2cx"
      },
      "source": [
        "## Overview\n",
        "\n",
        "### Imagen 4\n",
        "\n",
        "Imagen 4 on Vertex AI brings Google's state of the art generative AI capabilities to application developers. Imagen 4 is Google's highest quality text-to-image model to date. It's capable of creating images with astonishing detail and rendered text across a wide variety of styles. Learn more about [Imagen on Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/image/overview).\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "DrkcqHrrwMAo"
      },
      "source": [
        "In this tutorial, you will learn how to use the Google Gen AI SDK for Python to interact with the Imagen 4 , Imagen 4 Fast, and Imagen 4 Ultra models to generate images showcasing:\n",
        "\n",
        "- Stylistic variety\n",
        "- Multilingual prompt support & enhancement\n",
        "- High quality photorealism\n",
        "- Text rendering\n",
        "- Image watermarking\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "r11Gu7qNgx1p"
      },
      "source": [
        "## Get started\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "No17Cw5hgx12"
      },
      "source": [
        "### Install Google Gen AI SDK for Python\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "tFy3H3aPgx12"
      },
      "outputs": [],
      "source": [
        "%pip install --upgrade --quiet google-genai"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "dmWOrTJ3gx13"
      },
      "source": [
        "### Authenticate your notebook environment (Colab only)\n",
        "\n",
        "If you are running this notebook on Google Colab, run the following cell to authenticate your environment.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "NyKGtVQjgx13"
      },
      "outputs": [],
      "source": [
        "import sys\n",
        "\n",
        "if \"google.colab\" in sys.modules:\n",
        "    from google.colab import auth\n",
        "\n",
        "    auth.authenticate_user()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Ua6PDqB1iBSb"
      },
      "source": [
        "### Import libraries"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "yTiDo0lRh6sc"
      },
      "outputs": [],
      "source": [
        "from google import genai\n",
        "from google.genai import types"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "h_SlrGfc-d74"
      },
      "source": [
        "### Set up Google Cloud Project or API Key for Vertex AI\n",
        "\n",
        "You'll need to set up authentication by choosing **one** of the following methods:\n",
        "\n",
        "1.  **Use a Google Cloud Project:** Recommended for most users, this requires enabling the Vertex AI API in your Google Cloud project.\n",
        "    - [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com)\n",
        "    - Run the cell below to set your project ID and location.\n",
        "    - Read more about [Supported locations](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations)\n",
        "2.  **Use a Vertex AI API Key (Express Mode):** For quick experimentation.\n",
        "    - [Get an API Key](https://cloud.google.com/vertex-ai/generative-ai/docs/start/express-mode/overview)\n",
        "    - Run the cell further below to use your API key."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "NKuEJq_n_CxY"
      },
      "source": [
        "#### Option 1. Use a Google Cloud Project"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "6-0EZL74_GCA"
      },
      "outputs": [],
      "source": [
        "import os\n",
        "\n",
        "PROJECT_ID = \"[your-project-id]\"  # @param {type: \"string\", placeholder: \"[your-project-id]\", isTemplate: true}\n",
        "if not PROJECT_ID or PROJECT_ID == \"[your-project-id]\":\n",
        "    PROJECT_ID = str(os.environ.get(\"GOOGLE_CLOUD_PROJECT\"))\n",
        "\n",
        "LOCATION = os.environ.get(\"GOOGLE_CLOUD_REGION\", \"us-central1\")\n",
        "\n",
        "client = genai.Client(vertexai=True, project=PROJECT_ID, location=LOCATION)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "XxkJSQYx_JDZ"
      },
      "source": [
        "#### Option 2. Use a Vertex AI API Key (Express Mode)\n",
        "\n",
        "Uncomment the following block to use Express Mode"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "HDFLFepq_LMO"
      },
      "outputs": [],
      "source": [
        "# API_KEY = \"[your-api-key]\"  # @param {type: \"string\", placeholder: \"[your-api-key]\", isTemplate: true}\n",
        "\n",
        "# if not API_KEY or API_KEY == \"[your-api-key]\":\n",
        "#     raise Exception(\"You must provide an API key to use Vertex AI in express mode.\")\n",
        "\n",
        "# client = genai.Client(vertexai=True, api_key=API_KEY)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_YfYjZ_I_NjB"
      },
      "source": [
        "Verify which mode you are using."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Ps_M3F88_P8-"
      },
      "outputs": [],
      "source": [
        "if not client.vertexai:\n",
        "    print(\"Using Gemini Developer API.\")\n",
        "elif client._api_client.project:\n",
        "    print(\n",
        "        f\"Using Vertex AI with project: {client._api_client.project} in location: {client._api_client.location}\"\n",
        "    )\n",
        "elif client._api_client.api_key:\n",
        "    print(\n",
        "        f\"Using Vertex AI in express mode with API key: {client._api_client.api_key[:5]}...{client._api_client.api_key[-5:]}\"\n",
        "    )"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Sr2Y3lFwKW1M"
      },
      "source": [
        "### Define a helper function to display images"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "r_38e5rRKB6s"
      },
      "outputs": [],
      "source": [
        "import typing\n",
        "\n",
        "import IPython.display\n",
        "from PIL import Image as PIL_Image\n",
        "from PIL import ImageOps as PIL_ImageOps\n",
        "\n",
        "\n",
        "def display_image(\n",
        "    image,\n",
        "    max_width: int = 700,\n",
        "    max_height: int = 400,\n",
        ") -> None:\n",
        "    pil_image = typing.cast(PIL_Image.Image, image._pil_image)\n",
        "    if pil_image.mode != \"RGB\":\n",
        "        # RGB is supported by all Jupyter environments (e.g. RGBA is not yet)\n",
        "        pil_image = pil_image.convert(\"RGB\")\n",
        "    image_width, image_height = pil_image.size\n",
        "    if max_width < image_width or max_height < image_height:\n",
        "        # Resize to display a smaller notebook image\n",
        "        pil_image = PIL_ImageOps.contain(pil_image, (max_width, max_height))\n",
        "    IPython.display.display(pil_image)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VLmwIj2RD0Fx"
      },
      "source": [
        "### Load the Imagen 4 image generation models"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Fx2O_9h5sNAI"
      },
      "outputs": [],
      "source": [
        "generation_model = \"imagen-4.0-generate-001\"\n",
        "generation_model_fast = \"imagen-4.0-fast-generate-001\"\n",
        "generation_model_ultra = \"imagen-4.0-ultra-generate-001\""
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mvH2OTrK8IRS"
      },
      "source": [
        "### Imagen 4\n",
        "\n",
        "With Imagen 4, you can generate high quality images with improved prompt adherence and text rendering capabilities. Run the cell below to see an example of an image generated with Imagen 4 that includes specific text and taglines to be rendered within the image.\n",
        "\n",
        "You can configure the `aspect ratio` to any of the following:\n",
        "- `1:1`\n",
        "- `9:16`\n",
        "- `16:9`\n",
        "- `3:4`\n",
        "- `4:3`\n",
        "\n",
        "When using Imagen 4 you can set `number_of_images` to any value between 1 and 4.\n",
        "\n",
        "You can also set the `image_size` to `1K` or `2K`."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "KJqHuGqi31rE"
      },
      "outputs": [],
      "source": [
        "prompt = \"\"\"\n",
        "A white wall with two Art Deco travel posters mounted. First poster has the text: \"NEPTUNE\", tagline: \"The jewel of the solar system!' Second poster has the text: \"JUPITER\", tagline: \"Travel with the giants!\n",
        "\"\"\"\n",
        "\n",
        "image = client.models.generate_images(\n",
        "    model=generation_model,\n",
        "    prompt=prompt,\n",
        "    config=types.GenerateImagesConfig(\n",
        "        aspect_ratio=\"16:9\",\n",
        "        number_of_images=1,\n",
        "        image_size=\"2K\",\n",
        "        safety_filter_level=\"BLOCK_MEDIUM_AND_ABOVE\",\n",
        "        person_generation=\"ALLOW_ADULT\",\n",
        "    ),\n",
        ")\n",
        "\n",
        "display_image(image.generated_images[0].image)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "nDCthO_aoX0x"
      },
      "source": [
        "### Imagen 4 Fast\n",
        "\n",
        "With Imagen 4, you also have the option to use Imagen 4 Fast. These two model options give you the choice to optimize for quality and latency, depending on your use case.\n",
        "\n",
        "**Imagen 4:** Generates high quality images with natural lighting and increased photorealism.\n",
        "\n",
        "**Imagen 4 Fast:** Suitable for creating brighter images with a higher contrast."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "_RqB1mKunlPB"
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n",
        "\n",
        "prompt = \"\"\"\n",
        "an image of the New York skyline at sunset\n",
        "\"\"\"\n",
        "\n",
        "# Imagen 4 image generation\n",
        "image = client.models.generate_images(\n",
        "    model=generation_model,\n",
        "    prompt=prompt,\n",
        "    config=types.GenerateImagesConfig(\n",
        "        number_of_images=1,\n",
        "        aspect_ratio=\"3:4\",\n",
        "        image_size=\"2K\",\n",
        "        safety_filter_level=\"BLOCK_MEDIUM_AND_ABOVE\",\n",
        "        person_generation=\"ALLOW_ADULT\",\n",
        "    ),\n",
        ")\n",
        "\n",
        "# Imagen 4 Fast image generation\n",
        "fast_image = client.models.generate_images(\n",
        "    model=generation_model_fast,\n",
        "    prompt=prompt,\n",
        "    config=types.GenerateImagesConfig(\n",
        "        number_of_images=1,\n",
        "        aspect_ratio=\"3:4\",\n",
        "        image_size=\"2K\",\n",
        "        safety_filter_level=\"BLOCK_MEDIUM_AND_ABOVE\",\n",
        "        person_generation=\"ALLOW_ADULT\",\n",
        "    ),\n",
        ")\n",
        "\n",
        "# Display generated images\n",
        "fig, axis = plt.subplots(1, 2, figsize=(12, 6))\n",
        "axis[0].imshow(image.generated_images[0].image._pil_image)\n",
        "axis[0].set_title(\"Imagen 4\")\n",
        "axis[1].imshow(fast_image.generated_images[0].image._pil_image)\n",
        "axis[1].set_title(\"Imagen 4 Fast\")\n",
        "for ax in axis:\n",
        "    ax.axis(\"off\")\n",
        "plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "UND0wrdf3mGS"
      },
      "source": [
        "### High quality images with Imagen 4 Ultra\n",
        "\n",
        "Along with Imagen 4 and Imagen 4 Fast, you have the option to use Imagen 4 Ultra. This model will return exceptionally high quality images with latency as a tradeoff.\n",
        "\n",
        "When generating images of people you can also set the `safety_filter_level` and `person_generation` parameters accordingly:\n",
        "- `person_generation`\n",
        "  - `DONT_ALLOW`\n",
        "  - `ALLOW_ADULT`\n",
        "  - `ALLOW_ALL`\n",
        "- `safety_filter_level`\n",
        "  - `BLOCK_LOW_AND_ABOVE`\n",
        "  - `BLOCK_MEDIUM_AND_ABOVE`\n",
        "  - `BLOCK_ONLY_HIGH`\n",
        "  - `BLOCK_NONE`"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "7JBtrCfd1idI"
      },
      "outputs": [],
      "source": [
        "prompt = \"\"\"\n",
        "Photorealistic night scene: looking into a brightly lit, classic 1960s American diner from the cold street outside. The entire view is filtered through a large pane of glass streaked with rainwater. The neon 'DINER' sign outside casts colorful reflections on the wet pavement and the window itself. Moody, nostalgic, shallow depth of field emphasizing the window surface.\n",
        "\"\"\"\n",
        "\n",
        "image = client.models.generate_images(\n",
        "    model=generation_model_ultra,\n",
        "    prompt=prompt,\n",
        "    config=types.GenerateImagesConfig(\n",
        "        number_of_images=1,\n",
        "        aspect_ratio=\"1:1\",\n",
        "        image_size=\"2K\",\n",
        "        safety_filter_level=\"BLOCK_MEDIUM_AND_ABOVE\",\n",
        "        person_generation=\"ALLOW_ADULT\",\n",
        "    ),\n",
        ")\n",
        "\n",
        "display_image(image.generated_images[0].image)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "34oCrJAYniTJ"
      },
      "source": [
        "### Multilingual and prompt rewriter support\n",
        "\n",
        "Imagen 4 is also capable of processing text prompts in multiple languages. The following input values are supported for the text-prompt language:\n",
        "- English\n",
        "- Chinese (Simplified)\n",
        "- Chinese (Traditional)\n",
        "- Hindi\n",
        "- Japanese\n",
        "- Korean\n",
        "- Portuguese\n",
        "- Spanish\n",
        "- German\n",
        "- French\n",
        "\n",
        "The `imagen-4.0-generate-001` model offers the option to enhance your provided prompt. To utilize this feature, set `enhance_prompt` to True. A new, detailed prompt will be created from your original one to help generate higher quality images."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "_RqB1mKunlPB"
      },
      "outputs": [],
      "source": [
        "prompt = \"\"\"\n",
        "Una pintura al óleo impresionista de una taza de café sobre una mesa en una cocina, con las palabras 'buenos días' escritas en una fuente caprichosa en la taza.\n",
        "\"\"\"\n",
        "\n",
        "image = client.models.generate_images(\n",
        "    model=generation_model,\n",
        "    prompt=prompt,\n",
        "    config=types.GenerateImagesConfig(\n",
        "        number_of_images=1,\n",
        "        aspect_ratio=\"1:1\",\n",
        "        image_size=\"2K\",\n",
        "        enhance_prompt=True,\n",
        "        safety_filter_level=\"BLOCK_MEDIUM_AND_ABOVE\",\n",
        "        person_generation=\"ALLOW_ADULT\",\n",
        "    ),\n",
        ")\n",
        "\n",
        "# Print the enhanced prompt\n",
        "print(image.generated_images[0].enhanced_prompt)\n",
        "display_image(image.generated_images[0].image)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "hAeNPdyU9AlC"
      },
      "source": [
        "### Better text rendering\n",
        "\n",
        "Imagen 4 does a great job accurately rendering words, titles, and phrases in images. This could be particularly useful for comics, logo generation, flowcharts, flyers, and posters."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "DLmdtT8Q38fn"
      },
      "outputs": [],
      "source": [
        "prompt = \"\"\"\n",
        "A panel of a comic strip. A cute gray cat is talking to a bulldog. The cat appears to be slightly disgusted. The cat says in a talk bubble: \"You really seem to enjoy going outside. Fascinating.\" The dog responds by shrugging his shoulders. Well-articulated illustration with confident lines and shading.\n",
        "\"\"\"\n",
        "\n",
        "image = client.models.generate_images(\n",
        "    model=generation_model,\n",
        "    prompt=prompt,\n",
        "    config=types.GenerateImagesConfig(\n",
        "        number_of_images=1,\n",
        "        aspect_ratio=\"4:3\",\n",
        "        image_size=\"2K\",\n",
        "        safety_filter_level=\"BLOCK_MEDIUM_AND_ABOVE\",\n",
        "        person_generation=\"ALLOW_ADULT\",\n",
        "    ),\n",
        ")\n",
        "\n",
        "display_image(image.generated_images[0].image)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xGneutCN-mW5"
      },
      "source": [
        "### Add image watermark\n",
        "\n",
        "By default, a digital watermark, or [SynthID](https://deepmind.google/technologies/synthid/), is added to Imagen 4 images. If you would like to explicitly set the watermark to True, you can do so with the `add_watermark` parameter. You can also [verify a watermarked image](https://cloud.google.com/vertex-ai/generative-ai/docs/image/generate-images#watermark) via Vertex AI Studio."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "XtyEx1tYhB8h"
      },
      "outputs": [],
      "source": [
        "prompt = \"\"\"\n",
        "Design an elegant and symbolic movie poster for the period romance 'The Crimson Thread'. A close-up, artistic shot of two hands, almost touching, with a single, vibrant crimson thread winding between their fingers and subtly forming the title 'The Crimson Thread' within its loops and flows. The typography of the title should feel like flowy hand-stitched embroidery. The background is a soft-focus, de-saturated garden.\n",
        "\"\"\"\n",
        "\n",
        "image = client.models.generate_images(\n",
        "    model=generation_model,\n",
        "    prompt=prompt,\n",
        "    config=types.GenerateImagesConfig(\n",
        "        number_of_images=1,\n",
        "        aspect_ratio=\"1:1\",\n",
        "        image_size=\"2K\",\n",
        "        safety_filter_level=\"BLOCK_MEDIUM_AND_ABOVE\",\n",
        "        person_generation=\"ALLOW_ADULT\",\n",
        "        add_watermark=True,\n",
        "    ),\n",
        ")\n",
        "\n",
        "display_image(image.generated_images[0].image)"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "name": "imagen4_image_generation.ipynb",
      "toc_visible": true
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
