Enhancing Images with Styles and Quality Modifiers in Python

Introduction to Styles and Quality Modifiers

Welcome back! In the previous lesson, you learned how to craft effective prompts by focusing on the key components: subject, context, and style. This lesson builds on that foundation by introducing you to styles and quality modifiers, which help shape the final look of your generated images.

By the end of this lesson, you will understand how to combine these elements to create visually stunning and high-quality images using the Gemini API.

Understanding Quality Modifiers

Quality modifiers are descriptive keywords that guide the model toward a more polished or detailed output in terms of aesthetic and composition. Examples include:

  • "high-quality"
  • "high definition"
  • "HDR"
  • "high-detail"
  • "cinematic lighting"
  • "ultra-realistic"

It is important to note that these keywords affect the visual style and perceived detail of the generated image, but they do not change the technical resolution or dimensions (pixel count). While modifiers make the image look higher quality, the actual image size is controlled by the image_size parameter within the image_config.

For example, this prompt:

A photo of a corn stalk

may produce a simple image.

But this prompt:

A beautiful high-detail HDR photo of a corn stalk taken by a professional photographer

gives the model stronger visual guidance to include more intricate textures and better lighting within the standard output resolution.

Exploring Artistic Styles

Artistic styles define the visual approach of the generated image. You can use styles such as:

  • photorealistic
  • oil painting
  • watercolor
  • digital art
  • sketch
  • cyberpunk
  • fantasy illustration

For example:

A painting of a futuristic city

will likely produce a different visual result than:

A photorealistic aerial photo of a futuristic city

Combining Styles with Quality Modifiers: Code Example

from google import genai
from google.genai import types
import os
import time

GEMINI_IMAGE_MODEL = "gemini-3.1-flash-image"

api_key = os.getenv("GEMINI_API_KEY")

if not api_key:
    raise ValueError("GEMINI_API_KEY not found in environment variables. Set it before running the script.")

base_url = os.getenv("GEMINI_BASE_URL")

if not base_url:
    raise ValueError("GEMINI_BASE_URL not found in environment variables. Set it before running the script.")

client = genai.Client(
    api_key=api_key,
    http_options=types.HttpOptions(
        base_url=base_url,
    ),
)

style_quality_prompts = [
    "A beautiful landscape, photorealistic style, high-resolution details",
    "A portrait of a woman, oil painting style, high definition",
    "A futuristic cityscape, cyberpunk style, ultra-realistic, cinematic detail",
    "A serene beach scene, watercolor painting, high-quality details",
]

for index, prompt in enumerate(style_quality_prompts):
    response = client.models.generate_content(
        model=GEMINI_IMAGE_MODEL,
        contents=prompt,
        config=types.GenerateContentConfig(
            response_modalities=["IMAGE"],
            image_config=types.ImageConfig(
                aspect_ratio="1:1",
            )
        ),
    )

    image_parts = [part for part in response.parts if part.inline_data]

    if not image_parts:
        print(f"No image generated for prompt: {prompt}")
        continue

    image = image_parts[0].as_image()
    timestamp = int(time.time() * 1000)
    image_filename = f"image_{timestamp}_{index}.png"
    output_path = os.path.join("static", "images", image_filename)
    os.makedirs(os.path.dirname(output_path), exist_ok=True)
    image.save(output_path)
Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal