Gemini API 图像生成提示词教程

Gemini API 图像生成提示词教程

20250917-120352 20250917-120433

概述

本文档基于 Google Gemini API 官方文档,详细介绍如何使用 Gemini 2.5 Flash Image Preview 模型进行图像生成,重点讲解如何编写有效的提示词来获得高质量的生成图像。

基础配置

模型信息

  • 模型名称: gemini-2.5-flash-image-preview
  • 支持功能: 文本到图像生成、图像编辑、图像风格转换

基本调用方式

Python 示例:

response = client.models.generate_content(
    model="gemini-2.5-flash-image-preview",
    contents=[prompt],
)

JavaScript 示例:

const response = await genAI.getGenerativeModel({
    model: "gemini-2.5-flash-image-preview",
    contents: prompt,
});

提示指南和策略

用于生成图片的提示

1. 写实人物肖像

提示词示例:

A photorealistic close-up portrait of an elderly Japanese ceramicist with
deep, sun-etched wrinkles and a warm, knowing smile. He is carefully
inspecting a freshly glazed tea bowl. The setting is his rustic, sun-drenched 
workshop with pottery wheels and shelves of clay pots in the background. 
The scene is illuminated by soft, golden hour light streaming through a window, 
highlighting the fine texture of the clay and the focused expression on his face.

关键要素:

  • 具体的人物描述(年龄、职业、外貌特征)
  • 详细的动作和表情
  • 环境背景设置
  • 光照条件描述
  • 画面质感要求

2. 卡通风格设计

提示词示例:

A kawaii-style sticker of a happy red panda wearing a tiny bamboo hat. It's
munching on a green bamboo leaf. The design features bold, clean outlines,
simple cel-shading, and a vibrant color palette. The background must be white.

设计要点:

  • 明确指定艺术风格(kawaii-style)
  • 描述角色特征和动作
  • 指定设计元素(轮廓、着色方式)
  • 明确背景要求

3. 商业Logo设计

提示词示例:

Create a modern, minimalist logo for a coffee shop called 'The Daily Grind'.
The text should be in a clean, bold, sans-serif font. The design should
feature a simple, stylized icon of a coffee bean seamlessly integrated 
with the text. The color scheme is black and white.

Logo设计要素:

  • 品牌名称和定位
  • 字体风格要求
  • 图标元素描述
  • 色彩方案指定
  • 整体设计风格

4. 产品摄影

提示词示例:

A high-resolution, studio-lit product photograph of a minimalist ceramic
coffee mug in matte black, presented on a polished concrete surface. The
lighting is a three-point softbox setup designed to create soft, diffused 
highlights and eliminate harsh shadows. The camera angle is a slightly 
elevated 45-degree shot to showcase its clean lines. Ultra-realistic, 
with sharp focus on the steam rising from the coffee. Square image.

产品摄影要点:

  • 产品详细描述(材质、颜色、形状)
  • 背景和表面材质
  • 专业灯光设置
  • 拍摄角度和构图
  • 画质和焦点要求

5. 极简主义构图

提示词示例:

A minimalist composition featuring a single, delicate red maple leaf
positioned in the bottom-right of the frame. The background is a vast, empty
off-white canvas, creating significant negative space for text. Soft, 
diffused lighting from the top left. Square image.

极简设计特点:

  • 单一主体元素
  • 大量留白空间
  • 精确的位置描述
  • 柔和的光照效果
  • 明确的画面比例

6. 漫画风格场景

提示词示例:

A single comic book panel in a gritty, noir art style with high-contrast
black and white inks. In the foreground, a detective in a trench coat stands
under a flickering streetlamp, rain soaking his shoulders. In the background, 
the neon sign of a desolate bar reflects in a puddle. A caption box at the 
top reads "The city was a tough place to keep secrets." The lighting is harsh, 
creating a dramatic, somber mood. Landscape orientation.

漫画元素:

  • 明确的艺术风格(noir)
  • 场景层次描述(前景、背景)
  • 环境氛围营造
  • 文字内容设置
  • 情绪和色调控制

用于修改图片的提示

1. 添加装饰元素

提示词示例:

Using the provided image of my cat, please add a small, knitted wizard hat
on its head. Make it look like it's sitting comfortably and matches the soft
lighting of the original photo.

编辑要点:

  • 明确指出要修改的对象
  • 详细描述要添加的元素
  • 确保与原图风格一致

2. 替换特定物品

提示词示例:

Using the provided image of a living room, change only the blue sofa to be
a vintage, brown leather chesterfield sofa. Keep the rest of the room,
including lighting and perspective, exactly the same.

替换原则:

  • 精确指定要替换的物品
  • 详细描述新物品的特征
  • 强调保持其他元素不变

3. 艺术风格转换

提示词示例:

Transform the provided photograph of a modern city street at night into the 
artistic style of Vincent van Gogh's 'Starry Night'. Preserve the original 
composition of buildings and cars, but render all elements with swirling, 
impasto brushstrokes and a dramatic palette of deep blues and bright yellows.

风格转换要素:

  • 指定目标艺术风格
  • 保持原始构图
  • 描述新的视觉特征
  • 指定色彩方案

4. 服装合成

提示词示例:

Create a professional e-commerce fashion photo. Take the blue floral dress
from the first image and let the woman from the second image wear it.
Ensure the lighting, pose, and background create a cohesive, professional
product photograph suitable for online retail.

合成要求:

  • 明确指出素材来源
  • 描述合成效果
  • 确保专业质量标准

5. Logo应用

提示词示例:

Take the first image of the woman with brown hair, blue eyes, and a neutral
expression. Add the logo from the second image onto her black t-shirt.
Position it centered on the chest area, scaled appropriately, and ensure
it looks naturally printed on the fabric with realistic shadows and texture.

Logo应用要点:

  • 精确描述人物特征
  • 指定Logo位置和大小
  • 确保自然的视觉效果

提示词最佳实践

1. 结构化描述

推荐格式:

[主体描述] + [动作/姿态] + [环境/背景] + [光照条件] + [艺术风格] + [技术要求]

2. 关键词优先级

  1. 主体元素 – 最重要的描述对象
  2. 风格指定 – 艺术风格或视觉效果
  3. 环境设置 – 背景和场景
  4. 技术参数 – 分辨率、构图、光照

3. 具体性原则

好的示例:

  • "一只橙色短毛猫坐在木制窗台上"
  • "25岁的亚洲女性,长黑发,温和微笑"
  • "现代极简主义客厅,白色沙发,大理石茶几"

避免的示例:

  • "一只猫"
  • "一个人"
  • "房间"

4. 技术质量描述

常用质量词汇:

  • 高分辨率 / high-resolution
  • 4K / ultra-high definition
  • 专业摄影 / professional photography
  • 锐利细节 / sharp details
  • 完美光照 / perfect lighting
  • 超现实主义 / ultra-realistic

常见问题解决方案

1. 图像质量不佳

解决方法:

  • 添加质量描述词
  • 指定专业摄影技术
  • 明确光照要求

2. 风格不一致

解决方法:

  • 在提示词开头明确风格
  • 使用具体的艺术家或风格参考
  • 保持描述词的一致性

3. 构图不理想

解决方法:

  • 明确指定画面比例(方形、横向、纵向)
  • 描述主体在画面中的位置
  • 指定拍摄角度和视角

4. 细节缺失

解决方法:

  • 增加描述的具体性
  • 分层描述(前景、中景、背景)
  • 强调重要的视觉元素

高级技巧

1. 负面提示

虽然Gemini API不直接支持负面提示,但可以在正面描述中明确排除不需要的元素:

A clean, minimalist bedroom with white walls and natural lighting. 
No clutter, no bright colors, no decorative items on surfaces.

2. 情感表达

通过描述情绪和氛围来增强图像的感染力:

A melancholic autumn scene with golden leaves falling, creating a sense 
of nostalgia and peaceful solitude.

3. 多元素协调

确保所有描述元素之间的协调性:

A cozy coffee shop interior with warm wooden furniture, soft Edison bulb 
lighting, vintage leather chairs, and the gentle steam rising from fresh 
coffee cups, creating an inviting and comfortable atmosphere.

结语

有效的提示词编写是获得高质量AI生成图像的关键。通过遵循本教程的指导原则,结合具体的示例和最佳实践,您可以充分发挥Gemini API图像生成功能的潜力。

记住要:

  • 保持描述的具体性和详细性
  • 明确指定艺术风格和技术要求
  • 根据生成结果迭代优化提示词
  • 考虑图像的最终用途和目标受众

通过不断练习和实验,您将能够创作出令人印象深刻的AI生成图像。

© 版权声明
THE END
喜欢就支持一下吧