1. 介绍
OpenAI 的 GPT 图像生成模型专为生产级视觉效果和高度可控的创意工作流而设计。它们非常适合专业设计任务和迭代内容创作,并根据工作流需求,同时支持高质量渲染和低延迟使用场景。
核心能力包括:
- 高保真照片级写实,具备自然的采光、精确的材质和丰富的色彩渲染效果。
- 灵活的质量与延迟权衡,允许在较低设置下实现更快的生成,同时仍能超越前代图像模型的视觉质量。
- 稳健的面部与身份保持能力,适用于编辑、角色一致性维护和多步工作流。
- 可靠的文本渲染,实现图像内部清晰的文字、一致的布局和强对比度。
- 复杂的结构化视觉效果,包括信息图表、图示和多面板构图。
- 精准的风格控制与风格迁移,仅需极简提示词,即可支持从品牌设计系统到纯艺术风格等各种需求。
- 强大的现实世界知识与推理能力,能够准确描绘物体、环境和场景。
本指南介绍了针对 gpt-image-2 的提示词模式、最佳实践以及源自真实生产场景的示例。这是我们功能最强大的图像模型,具备更好的画质、改进的编辑性能以及对生产工作流更广泛的支持。low(低)质量设置特别适合对延迟敏感的用例,而 medium(中)和 high(高)则在对保真度要求极高时依然是合适的选择。
1.1 OpenAI 图像模型参数
本节提供了本指南涵盖的图像模型参考,重点关注:
- 模型名称
- 支持的
outputQuality值 - 支持的
input_fidelity值 - 支持的
size/ 分辨率行为 - 按工作流划分的推荐用例
模型总结
截至 2026 年 4 月 21 日,OpenAI 提供以下图像模型。
| 模型 | 输出质量 (outputQuality) | 输入保真度 (input_fidelity) | 分辨率 | 推荐用途 |
|---|---|---|---|---|
gpt-image-2 | low, medium, high | 已禁用。此模型不支持 input_fidelity,因为默认输出即为高保真度。 | 满足以下约束的任何分辨率 | 新构建项目的推荐默认值。用于最高质量的生成和编辑、文字密集的图像、照片级写实、合成、身份敏感的编辑,以及比起最低成本更看重减少重试次数的工作流。 |
gpt-image-1.5 | low, medium, high | low, high | 1024x1024, 1024x1536, 1536x1024, auto | 在迁移过程中为已有的经过验证的工作流保留。对于新工作,请优先使用 gpt-image-2,尤其是在对质量、编辑可靠性或灵活尺寸有要求时。 |
gpt-image-1 | low, medium, high | low, high | 1024x1024, 1024x1536, 1536x1024, auto | 仅限遗留兼容性。如果您正在启动新工作流或刷新提示词,请迁移到 gpt-image-2;仅在验证升级期间需要短期稳定性时保留 gpt-image-1。 |
gpt-image-1-mini | low, medium, high | low, high | 1024x1024, 1024x1536, 1536x1024, auto | 当成本和吞吐量是主要制约因素时使用:大规模批量变体生成、快速创意构思、预览、轻量级个性化,以及不需要最强生成或编辑性能的草稿素材。 |
gpt-image-2 尺寸选项
gpt-image-2 支持 size 参数传入的任何分辨率,只要满足以下所有约束:
- 最大边长必须小于
3840px - 两条边必须都是
16的倍数 - 长边与短边的比例不得大于
3:1 - 总像素不得超过
8,294,400 - 总像素不得少于
655,360
如果输出图像超过 2560x1440 像素(总计 3,686,400 像素,通常称为 2K),请将其视为实验性,因为超过此尺寸的结果可能会更加不稳定。
常用的 gpt-image-2 尺寸
以下是符合上述约束的有用参考点
| 标签 | 分辨率 | 备注 |
|---|---|---|
| 高清竖屏 (HD portrait) | 1024x1536 | 标准竖屏选项 |
| 高清横屏 (HD landscape) | 1536x1024 | 标准横屏选项 |
| 正方形 | 1024x1024 | 良好的通用默认选项 |
| 2K / QHD | 2560x1440 | 流行的宽屏格式,也是 gpt-image-2 的建议可靠性上限 |
| 4K / UHD | 3840x2160 | 实验性上限目标。如果最大边限制严格执行为 < 3840,请向下舍入至最接近的有效尺寸,例如 3824x2144 |
何时使用哪种模型
- 对于大多数生产工作流,请将
gpt-image-2作为默认模型。它是整体最强大的模型,也是目前使用gpt-image-1.5或gpt-image-1进行高质量输出的团队的正确升级目标。 - 当速度和单位经济效益是决定性因素时,请选择
gpt-image-2并配合quality: low。此设置在许多用例中画质良好,非常适合高容量生成和实验。您也可以尝试gpt-image-1-mini,但我们发现quality: low的效果同样出色。 - 仅在验证提示词迁移、进行输出回归测试或维护尚未准备好迁移的旧工作流时,保留
gpt-image-1.5或gpt-image-1。
从 gpt-image-1.5 和 gpt-image-1 的推荐升级路径
对于目前使用 gpt-image-1.5 或 gpt-image-1 的工作流,建议如下:
- 对于面向客户的资产、照片级写实生成、重编辑工作流、品牌敏感的创意、图文混合工作以及任何能够通过更好的首轮质量减少人工审查或重试的工作流,请升级到
gpt-image-2。 - 仅当主要目标是降低大规模探索性或低风险图像生成的成本时,才考虑使用
gpt-image-1-mini替代旧模型。 - 在迁移过程中,起初请保持提示词大致相同,仅在比较实际工作负载中的输出质量、延迟和重试率后,再进行调整。
2. 提示词基础
以下提示词基础知识适用于 GPT 图像生成模型。它们基于在生成、编辑、信息图表、广告、人物图像、UI 样机和合成工作流的 alpha 测试中反复出现的模式。
-
结构 + 目标:按一致的顺序编写提示词(背景/场景 → 主体 → 关键细节 → 约束),并包括预期的用途(广告、UI 样机、信息图表)以设置“模式”和润色水平。对于复杂请求,请使用短标签分段或换行,而不是一大段文本。
-
提示词格式:使用最易于维护的格式。极简提示词、描述性段落、JSON 结构、指令式提示词和基于标签的提示词只要意图和约束明确,效果都不错。对于生产系统,优先考虑易于快速阅读的模板,而不是复杂的语法。
-
特异性 + 质量线索:在材质、形状、纹理和视觉媒介(照片、水彩、3D 渲染)方面要具体,仅在需要时添加有针对性的“质量杠杆”(例如:胶片颗粒、纹理笔触、宏观细节)。对于照片写实,直接在提示词中包含“photorealistic”(照片级写实)以强烈激活模型的写实模式。类似的短语如“real photograph”(真实照片)、“taken on a real camera”(使用真实相机拍摄)、“professional photography”(专业摄影)或“iPhone photo”也有帮助,但详细的相机规格可能会被宽泛解释,因此主要用于高级外观和构图,而非精确的物理模拟。
-
延迟 vs 保真度:对于延迟敏感或高容量用例,从
quality="low"开始,评估它是否满足您的视觉要求。在许多情况下,它能以显著更快的生成速度提供足够的保真度。对于小字或密集文本、详细信息图表、特写肖像、身份敏感的编辑和高分辨率输出,请在上线前对比medium或high。 -
构图:指定取景和视角(特写、广角、俯视)、透视/角度(平视、低角度)以及照明/氛围(柔和漫射、黄金时刻、高对比度)来控制镜头。如果布局重要,请明确说明位置(例如:“logo 在右上角”、“主体居中,左侧留白”)。对于广角、电影感、弱光、雨天或霓虹灯场景,增加关于比例、氛围和色彩的额外细节,以免模型为了表面写实而牺牲氛围。
-
人物、姿势和动作:对于场景中的人物,描述比例、身体框架、视线和物体交互。示例:“全身可见,脚部包含在内”、“相对于桌子是儿童尺寸”、“看向打开的书,而不是镜头”、“双手自然握住车把”。这些细节有助于保持身体比例、动作几何结构和视线对齐。
-
约束(更改什么 vs 保留什么):明确说明排除项和不变项(例如:“无水印”、“无额外文字”、“无 logo/商标”、“保留身份/几何结构/布局/品牌元素”)。对于编辑,使用“仅更改 X”+“保持其他一切不变”,并在每次迭代时重复保留列表以减少偏移。如果编辑应该是局部的,还要说明不要改变饱和度、对比度、布局、箭头、标签、相机角度或周围物体。
-
图像中的文字:将文字放在引号或全大写中,并将排版细节(字体样式、大小、颜色、位置)指定为约束。对于棘手的词(品牌名称、不常见的拼写),逐字母拼写以提高字符准确性。对于小字、密集信息面板和多字体布局,请使用
medium或high质量。 -
多图像输入:通过索引和描述引用每个输入(“图像 1:产品照片……图像 2:风格参考……”)并描述它们如何交互(“将图像 2 的风格应用到图像 1”)。合成时,明确移动哪些元素(“把图像 1 中的鸟放在图像 2 的大象上”)。
-
迭代而非过度加载:长提示词效果很好,但从一个清晰的基础提示词开始,通过微小的、单项更改的后续指令进行细化(“让灯光更温暖”、“移除多余的树”、“恢复原始背景”)调试起来更容易。使用诸如“与之前风格相同”或“主体”之类的引用来利用上下文,但如果它们开始偏移,请重新指定关键细节。
3. 设置
运行一次即可。它会:
- 创建 API 客户端
- 在 images 文件夹中创建
output_images/。 - 添加一个小助手来保存 base64 图像。
将编辑中使用的任何参考图像放入 input_images/(或更新示例中的路径)。
import os
import base64
from openai import OpenAI
client = OpenAI()
os.makedirs("../../images/input_images", exist_ok=True)
os.makedirs("../../images/output_images", exist_ok=True)
def save_image(result, filename: str) -> None:
"""
Saves the first returned image to the given filename inside the output_images folder.
"""
image_base64 = result.data[0].b64_json
out_path = os.path.join("../../images/output_images", filename)
with open(out_path, "wb") as f:
f.write(base64.b64decode(image_base64))
from IPython.display import HTML, Image, display
def display_image_grid(items, width=240):
cards = []
for item in items:
title = item.get("title", "")
label = f'<div style="font-weight:600;margin-bottom:8px">{title}</div>' if title else ""
cards.append(
'<div style="text-align:center">'
+ label
+ f'<img src="{item["path"]}" width="{width}" style="max-width:100%;height:auto;" />'
+ '</div>'
)
display(HTML('<div style="display:flex;flex-wrap:wrap;gap:16px;align-items:flex-start">' + ''.join(cards) + '</div>'))
以下示例使用了我们最强大的图像模型 gpt-image-2。
4. 用例 — 生成 (文本 → 图像)
4.1 信息图表
使用信息图表为特定受众(学生、高管、客户或公众)解释结构化信息。示例包括解释说明图、海报、标注图、时间轴和“视觉维基”资产。对于密集布局或大量的图像内文字,建议将输出生成质量设置为“high”。
prompt = """
Create a detailed Infographic of the functioning and flow of an automatic coffee machine like a Jura.
From bean basket, to grinding, to scale, water tank, boiler, etc.
I'd like to understand technically and visually the flow.
"""
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "infographic_coffee_machine_gpt-image-2.png")
输出图像

4.2 图像翻译
用于将现有设计(广告、UI 截图、包装、信息图表)本地化为另一种语言,而无需从头重新构建布局。关键是保留除了文字之外的一切——保持排版风格、位置、间距和层级一致——同时逐字准确翻译,不要出现多余单词,除非必要否则不要重排版,也不要对 logo、图标或图像进行无意编辑。
prompt = """
Translate the text in the infographic to Spanish. Do not change any other aspect of the image.
"""
result = client.images.edit(
model="gpt-image-2",
image=[
open("../../images/output_images/infographic_coffee_machine_gpt-image-2.png", "rb"),
],
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "infographic_coffee_machine_sp_gpt-image-2.png")
输出图像

4.3 感觉“自然”的照片级写实图像
要获得令人信服的照片写实效果,像捕捉真实照片一样提示模型。使用摄影语言(镜头、照明、取景)并明确要求真实的纹理(毛孔、皱纹、织物磨损、瑕疵)。避免使用暗示摄影棚效果或摆拍的词语。当细节很重要时,请将质量设置为“high”。
prompt = """
Create a photorealistic candid photograph of an elderly sailor standing on a small fishing boat.
He has weathered skin with visible wrinkles, pores, and sun texture, and a few faded traditional sailor tattoos on his arms.
He is calmly adjusting a net while his dog sits nearby on the deck. Shot like a 35mm film photograph, medium close-up at eye level, using a 50mm lens.
Soft coastal daylight, shallow depth of field, subtle film grain, natural color balance.
The image should feel honest and unposed, with real skin texture, worn materials, and everyday detail. No glamorization, no heavy retouching.
"""
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "photorealism-gpt-image-2.png")
输出图像

4.4 世界知识
GPT 图像生成模型可以将强大的推理能力与世界知识相结合。例如,当被要求生成 1969 年 8 月发生在纽约州伯特利的场景时,它们可以推断出 Woodstock 音乐节,并在无需明确告知该事件的情况下制作出准确且符合背景的图像。
prompt = """
Create a realistic outdoor crowd scene in Bethel, New York on August 16, 1969.
Photorealistic, period-accurate clothing, staging, and environment.
"""
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "world_knowledge-gpt-image-2.png")
输出图像

4.5 Logo 生成
强大的 logo 生成源于清晰的品牌约束和简洁性。描述品牌的个性和用例,然后要求一个简洁、原创的标识,具备强烈的造型、平衡的负空间和跨尺寸的可扩展性。
您可以指定参数“n”来表示您想要生成的变体数量。
prompt = """
Create an original, non-infringing logo for a company called Field & Flour, a local bakery.
The logo should feel warm, simple, and timeless. Use clean, vector-like shapes, a strong silhouette, and balanced negative space.
Favor simplicity over detail so it reads clearly at small and large sizes. Flat design, minimal strokes, no gradients unless essential.
Plain background. Deliver a single centered logo with generous padding. No watermark.
"""
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1024x1536",
quality="medium",
n=4 # Generate 4 versions of the logo
)
# Save all 4 images to separate files
for i, item in enumerate(result.data, start=1):
image_base64 = item.b64_json
image_bytes = base64.b64decode(image_base64)
with open(f"../../images/output_images/logo_generation_{i}_gpt-image-2.png", "wb") as f:
f.write(image_bytes)
输出图像
| 选项 1 | 选项 2 | 选项 3 | 选项 4 |
|---|---|---|---|
![]() | ![]() | ![]() | ![]() |
4.6 广告生成
广告生成在提示词编写得像创意简报而非纯技术图像规格时效果最好。描述品牌、受众、文化、概念、构图和确切文案,然后让模型在这些边界内做出符合品味的创意决策。这对于早期营销活动探索非常有用,因为模型可以解读受众线索、推断艺术指导,并提出使广告感觉经过深思熟虑而非仅仅是渲染出来的视觉细节。
为了获得更好的结果,在同一个提示词中包含品牌定位、期望氛围、目标受众、场景和标语。如果文字必须出现在图像中,请准确引用它,并要求清晰、易读的排版。
prompt = """
Give me a cool in culture ad / fashion shot for a brand called Thread.
It's a hip young street brand. The ad shows a group of friends hanging out together with the tagline "Yours to Create."
Make it feel like a polished campaign image for a youth streetwear audience: stylish, contemporary, energetic, and tasteful.
Use clean composition, strong color direction, natural poses, and premium fashion photography cues.
Render the tagline exactly once, clearly and legibly, integrated into the ad layout.
No extra text, no watermarks, no unrelated logos.
"""
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "thread_ad_gpt-image-2.png")
输出图像

4.7 故事转连环画
对于故事转漫画生成,将叙事定义为一系列清晰的视觉节拍,每个面板一个。保持描述具体且专注于动作,以便模型能够将故事转化为可读、节奏良好的面板。
prompt = """
Create a short vertical comic-style reel with 4 equal-sized panels.
Panel 1: The owner leaves through the front door. The pet is framed in the window behind them, small against the glass, eyes wide, paws pressed high, the house suddenly quiet.
Panel 2: The door clicks shut. Silence breaks. The pet slowly turns toward the empty house, posture shifting, eyes sharp with possibility.
Panel 3: The house transformed. The pet sprawls across the couch like it owns the place, crumbs nearby, sunlight cutting across the room like a spotlight.
Panel 4: The door opens. The pet is seated perfectly by the entrance, alert and composed, as if nothing happened.
"""
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "comic_reel-gpt-image-2.png")
输出图像

4.8 UI 样机
UI 样机在您像描述现有产品一样描述它时效果最好。专注于布局、层级、间距和真实界面元素,避免概念艺术语言,这样结果看起来就像一个可用的、已发布的产品界面,而不是设计草图。
prompt = """
Create a realistic mobile app UI mockup for a local farmers market.
Show today’s market with a simple header, a short list of vendors with small photos and categories, a small “Today’s specials” section, and basic information for location and hours.
Design it to be practical, and easy to use. White background, subtle natural accent colors, clear typography, and minimal decoration.
It should look like a real, well-designed, beautiful app for a small local market.
Place the UI mockup in an iPhone frame.
"""
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "ui_farmers_market_gpt-image-2.png")
输出图像

4.9 科学/教育视觉素材
科学和教育视觉素材非常适合生物、化学、课堂讲解、扁平化科学图标系统、图示和学习资产。像指导性设计简报一样提示它们:定义受众、课程目标、视觉格式、所需的标签和科学约束。为了获得最佳结果,要求一个简洁、扁平的视觉系统,具备一致的图标风格、清晰的箭头、可读的标签和足够的留白,以便学生快速扫描概念。
当准确性很重要时,请明确列出所需组件并说明不应包含的内容。对于密集的标签、图表或将用于幻灯片或课程材料的资产,请使用 quality="high"。
prompt = """
Create a simple biology diagram titled "Cellular Respiration at a Glance" for high school students.
Show how glucose turns into energy inside a cell. Include glycolysis, the Krebs cycle, and the electron transport chain.
Use arrows to connect the steps, and label the main molecules: glucose, pyruvate, ATP, NADH, FADH2, CO2, O2, and H2O.
Make it look like a clean classroom handout or slide, with a white background, simple icons, clear labels, and easy-to-read text.
Avoid tiny text, extra decoration, or anything that makes the diagram hard to understand.
"""
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1536x1024",
quality="high",
)
save_image(result, "scientific_educational_cellular_respiration_gpt-image-2.png")
输出图像

4.10 幻灯片、图表、统计图和办公视觉素材
办公视觉素材在提示词写得像人工制品规格而非插图请求时效果最好。命名确切的交付成果(幻灯片、工作流图、统计图、页面图像),定义画布和层级,提供真实的文本或数据,并描述视觉语言。这些提示词应包含实用约束:可读的排版、润色过的间距、没有装饰性杂乱,以及没有通用的素材照片处理手法。
对于幻灯片、统计图和图表密集的资产,直接在提示词中包含数字和标签。对于幻灯片风格的输出,请使用横屏尺寸;当图像包含小字、图例、坐标轴或脚注时,使用 quality="high"。
prompt = """
Create one pitch-deck slide titled **"Market Opportunity"** that feels like a real Series A fundraising slide from a YC-backed startup.
Use a clean white background, modern sans-serif typography like Inter, and a crisp, minimal layout. The slide should include:
* A TAM/SAM/SOM concentric-circle diagram in muted blues and grays
* Specific, believable market sizing numbers:
* **TAM:** $42B
* **SAM:** $8.7B
* **SOM:** $340M
* A clean bar chart below showing market growth from **2021 to 2026**, with a subtle upward trend
* Small footnotes: **"AGI Research, 2024"** and **"Internal analysis"**
* A company logo placeholder in the bottom-right corner
The design should look like it belongs in a deck that actually raised money: highly readable text, clear data hierarchy, polished spacing, and professional startup-style visual language.
Avoid clip art, stock photography, gradients, shadows, decorative elements, or anything that feels generic or overdesigned.
"""
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1536x864",
quality="high",
)
save_image(result, "market_opportunity_slide_gpt-image-2.png")
输出图像

5. 用例 — 编辑 (文本 + 图像 → 图像)
5.1 风格迁移
当您想保留参考图像的视觉语言(调色板、纹理、笔触、胶片颗粒等)同时更改主体或场景时,风格迁移非常有用。为了获得最佳结果,描述必须保持一致的内容(风格线索)和必须更改的内容(新内容),并添加严格的约束,如背景、取景和“无额外元素”,以防止偏移。
prompt = """
Use the same style from the input image and generate a man riding a motorcycle on a white background.
"""
result = client.images.edit(
model="gpt-image-2",
image=[
open("../../images/input_images/pixels.png", "rb"),
],
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "motorcycle_gpt-image-2.png")
输入图像
![]()
输出图像

5.2 虚拟服装试穿
虚拟试穿是电子商务预览的理想选择,此时身份保持至关重要。关键是显式锁定人物(面部、体型、姿势、头发、表情),仅允许对服装进行更改,然后要求真实的贴合感(褶皱、遮挡)加上一致的照明/阴影,使服装看起来是自然穿戴的,而不是贴上去的。
prompt = """
Edit the image to dress the woman using the provided clothing images. Do not change her face, facial features, skin tone, body shape, pose, or identity in any way. Preserve her exact likeness, expression, hairstyle, and proportions. Replace only the clothing, fitting the garments naturally to her existing pose and body geometry with realistic fabric behavior. Match lighting, shadows, and color temperature to the original photo so the outfit integrates photorealistically, without looking pasted on. Do not change the background, camera angle, framing, or image quality, and do not add accessories, text, logos, or watermarks.
"""
result = client.images.edit(
model="gpt-image-2",
image=[
open("../../images/input_images/woman_in_museum.png", "rb"),
open("../../images/input_images/tank_top.png", "rb"),
open("../../images/input_images/jacket.png", "rb"),
open("../../images/input_images/tank_top.png", "rb"),
open("../../images/input_images/boots.png", "rb"),
],
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "outfit_gpt-image-2.png")
输入图像
| 全身照 | 项目 1 |
|---|---|
![]() | ![]() |
| 项目 2 | 项目 3 |
![]() | ![]() |
输出图像

5.3 绘图 → 图像(渲染)
草图转渲染工作流非常适合将粗略的草图转化为照片级写实的概念,同时保持原始意图。像对待规格书一样对待提示词:保留布局和透视,然后通过指定合理的材质、照明和环境来增加写实感。包括“不要添加新元素/文字”以避免创意的过度解读。
prompt = """
Turn this drawing into a photorealistic image.
Preserve the exact layout, proportions, and perspective.
Choose realistic materials and lighting consistent with the sketch intent.
Do not add new elements or text.
"""
result = client.images.edit(
model="gpt-image-2",
image=[
open("../../images/input_images/drawings.png", "rb"),
],
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "realistic_valley_gpt-image-2.png")
输入图像

输出图像

5.4 产品样机(干净背景 + 标签完整性)
产品提取和样机准备通常用于目录、市场和设计系统。成功取决于边缘质量(干净的轮廓,无边缘晕染/光晕)和标签完整性(文字保持清晰且不变)。对于 gpt-image-2,保持输出背景不透明,如果需要最终的透明资产,请使用下游的背景移除步骤。如果您想要写实而不改变风格,请仅要求轻微的润色,并可以选择在素背景上添加淡淡的接触阴影。
prompt = """
Extract the product from the input image and place it on a plain white opaque background.
Output: centered product, crisp silhouette, no halos/fringing.
Preserve product geometry and label legibility exactly.
Add only light polishing and a subtle realistic contact shadow.
Do not restyle the product; only remove background and lightly polish.
"""
result = client.images.edit(
model="gpt-image-2",
image=[
open("../../images/input_images/shampoo.png", "rb"),
],
prompt=prompt,
size="1024x1536",
quality="medium",
background="opaque",
)
save_image(result, "extract_product_gpt-image-2.png")
输入图像

输出图像

5.5 带有真实图像内文本的营销创意
带有真实图像内文本的营销创意非常适合快速的广告构思,但排版需要明确的约束。将确切文案放在引号中,要求逐字渲染(没有多余字符),并描述位置和字体样式。如果文本保真度不完美,请保持提示词严格并进行迭代——小幅度的措辞/布局调整通常能提高易读性。
prompt = """
Create a realistic billboard mockup of the shampoo on a highway scene during sunset.
Billboard text (EXACT, verbatim, no extra characters):
"Fresh and clean"
Typography: bold sans-serif, high contrast, centered, clean kerning.
Ensure text appears once and is perfectly legible.
No watermarks, no logos.
"""
result = client.images.edit(
model="gpt-image-2",
image=[
open("../../images/input_images/shampoo.png", "rb"),
],
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "billboard_gpt-image-2.png")
输入图像

输出图像

5.6 照明和天气变换
用于为了不同的情绪、季节或时间段变体重新布置照片(例如:晴天 → 阴天,白天 → 黄昏,晴朗 → 下雪),同时保持场景构图完好。关键是仅改变环境条件——照明方向/质量、阴影、大气、降水和地面潮湿程度——同时保留身份、几何结构、相机角度和物体位置,使其读起来仍然是同一张原始照片。
prompt = """
Make it look like a winter evening with snowfall.
"""
result = client.images.edit(
model="gpt-image-2",
input_fidelity="high",
image=[
open("../../images/output_images/billboard_gpt-image-2.png", "rb"),
],
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "billboard_winter_gpt-image-2.png")
输出图像

5.7 物体移除
场景中人物合成对于分镜脚本、营销活动和面部/身份保持至关重要的“如果……会怎样”场景非常有用。通过指定扎实的摄影外观(自然照明、可信细节、无电影级调色)来锚定写实感,并锁定主体中不能改变的部分。在可用时,更高的输入保真度有助于在更大的场景编辑中保持相似度。
prompt = """
Remove the flower from man's hand. Do not change anything else.
"""
result = client.images.edit(
model="gpt-image-2",
input_fidelity="high",
image=[
open("../../images/output_images/man_with_blue_hat.png", "rb"),
],
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "man_with_no_flower_gpt-image-2.png")
输入和输出图像
| 原始输入 | 输出图像 |
|---|---|
![]() | ![]() |
5.8 将人物插入场景
场景中人物合成对于分镜脚本、营销活动和面部/身份保持至关重要的“如果……会怎样”场景非常有用。通过指定扎实的摄影外观(自然照明、可信细节、无电影级调色)来锚定写实感,并锁定主体中不能改变的部分。在可用时,更高的输入保真度有助于在更大的场景编辑中保持相似度。
prompt = """
Generate a highly realistic action scene where this person is running away from a large, realistic brown bear attacking a campsite. The image should look like a real photograph someone could have taken, not an overly enhanced or cinematic movie-poster image.
She is centered in the image but looking away from the camera, wearing outdoorsy camping attire, with dirt on her face and tears in her clothing. She is clearly afraid but focused on escaping, running away from the bear as it destroys the campsite behind her.
The campsite is in Yosemite National Park, with believable natural details. The time of day is dusk, with natural lighting and realistic colors. Everything should feel grounded, authentic, and unstyled, as if captured in a real moment. Avoid cinematic lighting, dramatic color grading, or stylized composition.
"""
result = client.images.edit(
model="gpt-image-2",
input_fidelity="high",
image=[
open("../../images/input_images/woman_in_museum.png", "rb"),
],
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "scene_gpt-image-2.png")
输出图像
from IPython.display import Image, display
display(Image(filename="../../images/output_images/scene_gpt-image-2.png", width=500))
5.9 多图像引用与合成
用于将多个输入的元素组合成单个、可信的图像——非常适合“将此物体/人物插入那个场景”的工作流,而无需重新生成所有内容。关键是明确指定要移植什么(图像 2 中的狗),它应该去哪里(就在图像 1 中的女人旁边),以及必须保持不变的内容(场景、背景、取景),同时匹配照明、透视、比例和阴影,使合成看起来像是自然捕捉在原始照片中的。
prompt = """
Place the dog from the second image into the setting of image 1, right next to the woman, use the same style of lighting, composition and background. Do not change anything else.
"""
result = client.images.edit(
model="gpt-image-2",
input_fidelity="high",
image=[
open("../../images/output_images/test_woman.png", "rb"),
open("../../images/output_images/test_woman_2.png", "rb"),
],
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "test_woman_with_dog_gpt-image-2.png")
输入和输出图像
| 原始输入 | 移除红条纹 | 更改帽子颜色 |
|---|---|---|
![]() | ![]() | ![]() |
6. 其他高价值用例
6.1 室内设计“置换”(精准编辑)
用于在真实空间中可视化家具或装饰变化,而无需重新渲染整个场景。目标是外科手术般的写实感:交换单个物体,同时保留相机角度、照明、阴影和周围环境,使编辑看起来像真实照片,而不是重新设计。
prompt = """
In this room photo, replace ONLY white with chairs made of wood.
Preserve camera angle, room lighting, floor shadows, and surrounding objects.
Keep all other aspects of the image unchanged.
Photorealistic contact shadows and fabric texture.
"""
result = client.images.edit(
model="gpt-image-2",
image=[
open("../../images/input_images/kitchen.jpeg", "rb"),
],
prompt=prompt,
size="1536x1024",
quality="medium",
)
save_image(result, "kitchen-chairs_gpt-image-2.png")
输入和输出图像
| 输入图像 | 输出图像 |
|---|---|
![]() | ![]() |
6.2 3D 弹出式节日贺卡(产品风格样机)
季节性营销概念和打印预览的理想选择。强调触觉写实感——纸张层、纤维、折痕和柔和的摄影棚照明——使结果读起来像是被拍摄的物理产品,而不是平面插图。
scene_description = (
"a cozy Christmas scene with an old teddy bear sitting inside a keepsake box, "
"slightly worn fur, soft stitching repairs, placed near a window with falling snow outside. "
"The scene suggests the child has grown up, but the memories remain."
)
short_copy = "Merry Christmas — some memories never fade."
prompt = f"""
Create a Christmas holiday card illustration.
Scene:
{scene_description}
Mood:
Warm, nostalgic, gentle, emotional.
Style:
Premium holiday card photography, soft cinematic lighting,
realistic textures, shallow depth of field,
tasteful bokeh lights, high print-quality composition.
Constraints:
- Original artwork only
- No trademarks
- No watermarks
- No logos
Include ONLY this card text (verbatim):
"{short_copy}"
"""
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "christmas_holiday_card_teddy_gpt-image-2.png")
输出图像

6.3 可收藏手办/毛绒钥匙扣(周边概念)
用于早期的周边创意构思和提案视觉素材。专注于高端产品摄影线索(材质、包装、印刷清晰度),同时保持设计原创且不侵权。非常适合快速测试多个角色或包装变体。
# ---- Inputs ----
character_description = (
"a vintage-style toy propeller airplane with rounded wings, "
"a front-mounted spinning propeller, slightly worn paint edges, "
"classic childhood proportions, designed as a nostalgic holiday collectible"
)
short_copy = "Christmas Memories Edition"
# ---- Prompt ----
prompt = f"""
Create a collectible action figure of {character_description}, in blister packaging.
Concept:
A nostalgic holiday collectible inspired by the simple toy airplanes
children used to play with during winter holidays.
Evokes warmth, imagination, and childhood wonder.
Style:
Premium toy photography, realistic plastic and painted metal textures,
studio lighting, shallow depth of field,
sharp label printing, high-end retail presentation.
Constraints:
- Original design only
- No trademarks
- No watermarks
- No logos
Include ONLY this packaging text (verbatim):
"{short_copy}"
"""
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "christmas_collectible_toy_airplane_gpt-image-2.png")
输出图像

6.4 角色一致性的童书艺术(多图像工作流)
专为角色漂移不可接受的多页插图流水线设计。可重用的“角色锚点”确保跨场景、姿势和页面的视觉连续性,同时允许环境和叙事变化。
1️⃣ 角色锚点 — 确立可重用的主要角色
目标:锁定角色的外观、比例、服装和色调。
# ---- Inputs ----
prompt = """
Create a children’s book illustration introducing a main character.
Character:
A young, storybook-style hero inspired by a little forest outlaw,
wearing a simple green hooded tunic, soft brown boots, and a small belt pouch.
The character has a kind expression, gentle eyes, and a brave but warm demeanor.
Carries a small wooden bow used only for helping, never harming.
Theme:
The character protects and rescues small forest animals like squirrels, birds, and rabbits.
Style:
Children’s book illustration, hand-painted watercolor look,
soft outlines, warm earthy colors, whimsical and friendly.
Proportions suitable for picture books (slightly oversized head, expressive face).
Constraints:
- Original character (no copyrighted characters)
- No text
- No watermarks
- Plain forest background to clearly showcase the character
"""
# ---- Image generation ----
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "childrens_book_illustration_1_gpt-image-2.png")
输出图像

2️⃣ 故事延续 — 重用角色,推进叙事
目标:相同角色,新场景 + 动作。角色外观必须保持不变。
# ---- Inputs ----
prompt = """
Continue the children’s book story using the same character.
Scene:
The same young forest hero is gently helping a frightened squirrel
out of a fallen tree after a winter storm.
The character kneels beside the squirrel, offering reassurance.
Character Consistency:
- Same green hooded tunic
- Same facial features, proportions, and color palette
- Same gentle, heroic personality
Style:
Children’s book watercolor illustration,
soft lighting, snowy forest environment,
warm and comforting mood.
Constraints:
- Do not redesign the character
- No text
- No watermarks
"""
# ---- Image generation ----
result = client.images.edit(
model="gpt-image-2",
image=[
open("../../images/output_images/childrens_book_illustration_1_gpt-image-2.png", "rb"), # use image from step 1
],
prompt=prompt,
size="1024x1536",
quality="medium",
)
save_image(result, "childrens_book_illustration_2_gpt-image-2.png")
输出图像

结论
在本手册中,我们演示了如何使用 GPT 图像生成模型构建在真实生产环境中稳健的高质量、可控图像生成和编辑工作流。Cookbook 强调提示词结构、明确的约束和小步迭代更改作为控制写实感、布局、文字准确性和身份保持的主要工具。我们涵盖了生成和编辑模式,范围包括信息图表、照片写实、UI 样机、logo、翻译、风格迁移、虚拟试穿、合成和照明更改。在整个示例中,本手册强化了明确区分什么应该改变与什么必须保持不变的重要性,并在每次迭代中重申这些不变项以防止偏移。我们还强调了质量和输入保真度设置如何根据用例在延迟和视觉精度之间进行审慎的权衡。总之,这些示例构成了一套实用的、可重复的剧本,用于在生产图像工作流中应用 GPT 图像生成模型。














