Gpt-image-1.5 提示词指南:掌握AI图像生成技巧
技术背景
随着生成式 AI 的快速发展,图像生成模型已从实验性工具演变为生产级应用的核心组件。gpt-image-1.5 作为 OpenAI 最新推出的图像模型,在真实感、文本渲染、身份保持和复杂结构化视觉方面显著提升,适用于广告、电商、UI 设计、内容创作等场景。然而,模型输出质量高度依赖提示词设计,开发者常因提示词模糊、约束不足或迭代策略不当而无法获得理想结果。本教程旨在填补这一空白,提供系统化的提示词工程方法论,帮助开发者充分利用模型能力,构建可控、可复现的图像生成与编辑流水线。
核心原理
gpt-image-1.5 基于扩散模型架构,通过文本编码器将提示词转换为语义向量,引导图像生成过程。其核心能力包括:1) 高保真照片级真实感,通过自然光照、材质和色彩渲染实现;2) 强大的文本渲染,支持图像内清晰文字;3) 身份保持,通过面部特征和风格锁定实现多步骤编辑;4) 世界知识推理,可理解隐含上下文(如历史事件)。提示词通过结构化描述(背景/场景→主体→关键细节→约束)控制生成方向,质量参数(quality)和输入保真度(input_fidelity)则调节生成速度与视觉精度。编辑模式基于图像编码器与文本条件,通过保留不变项和指定更改项实现精准修改。
架构分析
系统架构分为三层:1) 客户端层:使用 OpenAI Python SDK 创建 API 客户端,封装图像生成(generate)和编辑(edit)接口;2) 服务层:模型处理文本和图像输入,输出 base64 编码的图像数据;3) 存储层:通过辅助函数将图像保存至本地文件系统。关键设计决策包括:使用 os.makedirs 确保目录存在,save_image 函数解耦图像解码与保存逻辑,便于复用。编辑场景中,通过多图像输入(image 参数列表)支持风格迁移、虚拟试穿等复杂合成,并通过 prompt 中的索引和描述明确各输入的角色。质量参数(quality)和输入保真度(input_fidelity)作为可调杠杆,平衡延迟与视觉精度。
完整实战教程
Gpt-image-1.5 提示词指南
简介
Gpt-image-1.5 是一个强大的 AI 图像生成模型,能够根据文本提示词创建高质量的图像。本指南将介绍如何编写有效的提示词,以充分利用该模型的潜力。
提示词的基本结构
一个有效的提示词通常包含以下部分:
- 主体:描述图像的主要对象或场景。
- 风格:指定艺术风格或媒介(如油画、水彩、照片等)。
- 细节:添加颜色、光线、构图等细节。
- 情感或氛围:传达图像想要表达的情绪。
编写提示词的步骤
- 明确目标:确定您想要生成的图像类型。
- 描述主体:用清晰的语言描述主体,包括其属性、动作和位置。
- 选择风格:指定风格,如“写实”、“卡通”、“印象派”等。
- 添加细节:包括颜色、光照、视角、背景等。
- 调整语气:使用形容词和副词来增强描述。
示例
简单示例
- 提示词:一只猫坐在窗台上。
- 结果:生成一张简单的猫的图像。
详细示例
- 提示词:一只橘色的猫坐在阳光明媚的窗台上,背景是模糊的城市景观,采用水彩风格,光线柔和,氛围宁静。
- 结果:生成一张更具艺术感和细节的图像。
常见错误及避免方法
- 过于模糊:避免使用“一个东西”这样的描述,应具体化。
- 过度复杂:不要堆砌过多元素,以免模型混淆。
- 忽略风格:如果不指定风格,模型可能默认使用写实风格。
高级技巧
- 使用对比:如“明亮与黑暗”、“粗糙与光滑”等。
- 引用艺术家:如“以梵高的风格”或“类似宫崎骏的动画”。
- 利用负面提示:指定不希望出现的元素,如“没有文字”。
结论
编写好的提示词是生成理想图像的关键。通过实践和调整,您将能够更好地控制 Gpt-image-1.5 的输出。不断尝试,发现更多可能性。
1. 引言
gpt-image-1.5 是我们最新的图像生成模型,专为生产级视觉和高度可控的创意工作流而设计。它在真实感、准确性和可编辑性方面带来了重大改进,使其非常适合专业设计任务和迭代内容创作。与前代产品相比,它在真实感、准确性和可编辑性方面都有显著提升,并支持高质量渲染和低延迟用例。
主要能力包括:
- 高保真照片级真实感,具有自然光照、准确材质和丰富色彩渲染
- 灵活的质量-延迟权衡,允许在较低设置下更快生成,同时仍超越前代图像模型的视觉质量
- 强大的面部和身份保留,适用于编辑、角色一致性和多步骤工作流
- 可靠的文本渲染,图像内文字清晰、布局一致、对比度强
- 复杂的结构化视觉,包括信息图、图表和多面板构图
- 精确的风格控制和风格迁移,只需最少的提示,支持从品牌设计系统到美术风格的一切
- 强大的现实世界知识和推理能力,能够准确描绘物体、环境和场景
本指南重点介绍提示模式、最佳实践以及来自真实生产用例的示例提示。
2. 提示基础
* 结构 + 目标: 以一致的顺序(背景/场景 → 主体 → 关键细节 → 约束)编写提示,并包含预期用途(广告、UI 模型、信息图)以设定“模式”和精细程度。对于复杂请求,使用简短的标签段或换行符,而不是一个长段落。
* 具体性 + 质量提示: 具体说明材质、形状、纹理和视觉媒介(照片、水彩、3D 渲染),并仅在需要时添加有针对性的“质量杠杆”(例如,*胶片颗粒*、*纹理笔触*、*微距细节*)。对于照片级真实感,相机/构图术语(镜头、光圈感、光照)通常比通用的“8K/超详细”更可靠地引导真实感。
* 延迟与保真度: 对于延迟敏感或高容量的用例,首先设置 quality="low" 并评估它是否满足您的视觉要求。在许多情况下,它提供了足够的保真度,同时生成速度显著提高。
* 构图: 指定取景和视角(特写、广角、俯视)、透视/角度(平视、低角度)以及光照/氛围(柔光、黄金时刻、高对比度)来控制镜头。如果布局重要,请明确放置位置(例如,“右上角标志”、“主体居中,左侧留白”)。
* 约束(更改与保留): 明确说明排除项和不变量(例如,“无水印”、“无额外文本”、“无标志/商标”、“保留身份/几何/布局/品牌元素”)。对于编辑,使用“仅更改 X”+“保持其他一切不变”,并在每次迭代中重复保留列表以减少漂移。
* 图像中的文本: 将文字文本放在引号或全大写中,并指定排版细节(字体样式、大小、颜色、位置)作为约束。对于棘手单词(品牌名称、不常见拼写),逐字母拼写以提高字符准确性。
* 多图像输入: 通过索引和描述引用每个输入(“图像 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))
4. 使用场景 — 生成(文本 → 图像)
4.1 信息图
使用信息图为特定受众(学生、高管、客户或公众)解释结构化信息。示例包括解说图、海报、带标签的图表、时间线和“可视化维基”资产。对于密集布局或图像内文字较多的情况,建议将输出生成质量设置为“高”。
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-1.5",
prompt=prompt
)
save_image(result, "infographic_coffee_machine.png")

4.2 图像中的翻译
用于将现有设计(广告、UI 截图、包装、信息图)本地化为另一种语言,而无需从头重建布局。关键在于除文本外保留一切——保持排版风格、位置、间距和层级一致——同时逐字准确翻译,不添加多余词语,除非必要否则不重新排版,并且不意外修改徽标、图标或图像。
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-1.5",
image=[
open("../../images/output_images/infographic_coffee_machine.png", "rb"),
],
prompt=prompt
)
save_image(result, "infographic_coffee_machine_sp.png")
输出图像:

4.3 逼真且感觉“自然”的图像
要获得可信的逼真效果,请像在拍摄真实照片时那样提示模型。使用摄影语言(镜头、光线、构图),并明确要求真实的纹理(毛孔、皱纹、织物磨损、瑕疵)。避免使用暗示影棚修饰或摆拍的词语。当细节很重要时,设置 quality="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-1.5",
prompt=prompt,
quality="high"
)
save_image(result, "photorealism.png")
输出图像:

4.4 世界知识
GPT-image-1.5 内置了推理能力和强大的世界知识。例如,当被要求生成一个设定在1969年8月纽约贝瑟尔的场景时,它能够推断出伍德斯托克音乐节,并在未被明确告知该事件的情况下,生成准确且符合情境的图像。
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-1.5",
prompt=prompt
)
save_image(result, "world_knowledge.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-1.5",
prompt=prompt,
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}.png", "wb") as f:
f.write(image_bytes)
输出图像:
| 选项 1 | 选项 2 | 选项 3 | 选项 4 |
|:--------:|:--------:|:--------:|:--------:|
|
|
|
### 3.2 数据预处理
在将数据输入模型之前,需要进行一些预处理步骤。首先,我们将文本转换为小写,并去除标点符号。然后,我们使用分词器将文本分割成单词或子词。最后,我们将这些词转换为模型可以理解的数值表示。
import re
from transformers import AutoTokenizer
def preprocess_text(text):
text = text.lower()
text = re.sub(r'[^a-z0-9\s]', '', text)
return text
tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased')
def tokenize_text(text):
return tokenizer(text, padding=True, truncation=True, return_tensors='pt')
3.3 模型架构
我们使用一个预训练的Transformer模型作为基础,并在其之上添加一个分类头。分类头通常是一个全连接层,将模型的输出映射到类别数量。
from transformers import AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=2)
3.4 训练循环
训练循环包括前向传播、计算损失、反向传播和更新参数。我们使用AdamW优化器,并设置学习率调度器。
from transformers import AdamW, get_linear_schedule_with_warmup
optimizer = AdamW(model.parameters(), lr=2e-5)
total_steps = len(train_dataloader) * epochs
scheduler = get_linear_schedule_with_warmup(optimizer, num_warmup_steps=0, num_training_steps=total_steps)
for epoch in range(epochs):
for batch in train_dataloader:
outputs = model(**batch)
loss = outputs.loss
loss.backward()
optimizer.step()
scheduler.step()
optimizer.zero_grad()
3.5 评估
在验证集上评估模型性能,计算准确率、精确率、召回率和F1分数。
from sklearn.metrics import accuracy_score, precision_recall_fscore_support
def evaluate(model, dataloader):
model.eval()
predictions = []
true_labels = []
for batch in dataloader:
with torch.no_grad():
outputs = model(**batch)
logits = outputs.logits
preds = torch.argmax(logits, dim=-1)
predictions.extend(preds.cpu().numpy())
true_labels.extend(batch['labels'].cpu().numpy())
accuracy = accuracy_score(true_labels, predictions)
precision, recall, f1, _ = precision_recall_fscore_support(true_labels, predictions, average='binary')
return accuracy, precision, recall, f1
3.6 超参数调优
超参数如学习率、批量大小和训练轮数对模型性能有显著影响。我们可以使用网格搜索或随机搜索来找到最佳组合。
from sklearn.model_selection import ParameterGrid
param_grid = {
'learning_rate': [1e-5, 2e-5, 3e-5],
'batch_size': [16, 32],
'epochs': [3, 5]
}
best_score = 0
for params in ParameterGrid(param_grid):
# 训练和评估模型
# 记录最佳参数
3.7 模型保存与加载
训练完成后,保存模型权重和分词器,以便后续使用。
model.save_pretrained('./my_model')
tokenizer.save_pretrained('./my_model')
加载模型时:
from transformers import AutoModelForSequenceClassification, AutoTokenizer
model = AutoModelForSequenceClassification.from_pretrained('./my_model')
tokenizer = AutoTokenizer.from_pretrained('./my_model')
3.8 推理
在推理阶段,我们使用训练好的模型对新样本进行预测。
def predict(text):
processed = preprocess_text(text)
inputs = tokenizer(processed, return_tensors='pt')
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
pred = torch.argmax(logits, dim=-1).item()
return pred
3.9 常见问题与解决方案
- 过拟合:可以通过增加数据量、使用正则化(如Dropout)或早停来缓解。
- 类别不平衡:可以使用加权损失函数或过采样/欠采样技术。
- 训练速度慢:可以使用混合精度训练或分布式训练。
3.10 总结
本节介绍了使用Transformer进行文本分类的完整流程,包括数据预处理、模型构建、训练、评估和推理。通过调整超参数和采用适当的策略,可以显著提升模型性能。
4.6 故事到漫画条
对于故事到漫画的生成,将叙事定义为一系列清晰的视觉节拍,每个面板一个。保持描述具体且以动作为中心,以便模型能够将故事转化为可读、节奏良好的面板。
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-1.5",
prompt=prompt
)
save_image(result, "comic_reel.png")
输出图像:

4.7 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-1.5",
prompt=prompt
)
save_image(result, "ui_farmers_market.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-1.5",
image=[
open("../../images/input_images/pixels.png", "rb"),
],
prompt=prompt
)
save_image(result, "motorcycle.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-1.5",
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
)
save_image(result, "outfit.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-1.5",
image=[
open("../../images/input_images/drawings.png", "rb"),
],
prompt=prompt
)
save_image(result, "realistic_valley.png")
输入图像:

输出图像:

5.4 产品模型图(透明背景 + 标签完整性)
产品提取和样机准备通常用于目录、市场平台和设计系统。其成功取决于边缘质量(干净的轮廓,无边缘杂色/光晕)和标签完整性(文字保持清晰且不变)。如果您希望在不重新设计的情况下获得真实感,请仅要求轻度润饰,并可选地添加一个尊重 alpha 通道的细微接触阴影。
prompt = """
Extract the product from the input image.
Output: transparent background (RGBA PNG), crisp silhouette, no halos/fringing.
Preserve product geometry and label legibility exactly.
Optional: subtle, realistic contact shadow in the alpha (no hard cut line).
Do not restyle the product; only remove background and lightly polish.
"""
result = client.images.edit(
model="gpt-image-1.5",
image=[
open("../../images/input_images/shampoo.png", "rb"),
],
prompt=prompt
)
save_image(result, "extract_product.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-1.5",
image=[
open("../../images/input_images/shampoo.png", "rb"),
],
prompt=prompt
)
save_image(result, "billboard.png")
输入图像:

输出图像:

5.6 光照与天气变换
用于重新调整照片以呈现不同的情绪、季节或一天中的时间变化(例如,晴天→阴天,白天→黄昏,晴朗→雪天),同时保持场景构图不变。关键在于仅改变环境条件——光照方向/质量、阴影、氛围、降水和地面湿度——同时保留身份、几何形状、相机角度和物体位置,使其仍然看起来是同一张原始照片。
prompt = """
Make it look like a winter evening with snowfall.
"""
result = client.images.edit(
model="gpt-image-1.5",
input_fidelity="high",
quality="high",
image=[
open("../../images/output_images/billboard.png", "rb"),
],
prompt=prompt
)
save_image(result, "billboard_winter.png")
输出图像:

5.7 对象移除
人物场景合成对于故事板、广告活动和“假设”场景非常有用,在这些场景中,面部/身份保持至关重要。通过指定基于现实的摄影外观(自然光、可信细节、无电影调色)来锚定真实感,并锁定主体不可改变的部分。当可用时,更高的输入保真度有助于在较大的场景编辑中保持相似性。
prompt = """
Remove the tree logo from the white t-shirt of the man. Do not change anything else.
"""
prompt = """
Remove the red stripes from the white t-shirt of the man. Do not change anything else.
"""
prompt = """
Change the color of thered hat to light blue as velvet. Do not change anything else.
"""
result = client.images.edit(
model="gpt-image-1.5",
input_fidelity="high",
quality="high",
image=[
open("../../images/output_images/man_with_blue_hat.png", "rb"),
],
prompt=prompt
)
save_image(result, "man_with_no_flower.png")
| 原始输入 | 去除红色条纹 | 更换帽子颜色 |
|:------------:|:--------------:|:--------------:|
|
|
|
|
5.8 将人物插入场景中
现在我们已经有了一个角色,并且知道如何生成场景,接下来就是如何将角色无缝地融入到场景中。这不仅仅是简单的叠加,而是需要考虑到光线、透视、比例和交互等多个方面。
5.8.1 理解场景与角色的关系
在将角色插入场景之前,首先要明确场景的基调、光线方向和空间布局。角色应该与场景中的元素产生互动,比如站在地面上、坐在椅子上,或者与场景中的物体有遮挡关系。
5.8.2 使用图层和蒙版
在图像编辑软件中,将角色作为单独的图层导入,然后使用蒙版来调整角色的边缘,使其与场景融合。特别注意边缘的羽化,避免生硬的边界。
5.8.3 调整光线和阴影
观察场景中的光源位置,为角色添加相应的阴影和高光。如果场景是逆光,角色的边缘应该有光晕效果;如果是侧光,则角色的一侧应该有明显的阴影。
5.8.4 匹配透视和比例
确保角色的透视角度与场景一致。如果场景是俯视视角,角色也应该以俯视的角度呈现。同时,角色的尺寸要与场景中的参照物相匹配,避免过大或过小。
5.8.5 添加交互元素
让角色与场景中的物体产生互动,比如手持物品、触碰物体或与环境中的元素有视线交流。这能增强真实感和故事性。
5.8.6 最终检查
完成插入后,从整体上检查画面是否和谐。注意色彩平衡、细节一致性,以及角色与场景的融合度。必要时进行微调,直到满意为止。
通过以上步骤,你可以将人物自然地插入到任何场景中,创造出令人信服的视觉效果。
人物场景合成对于故事板、广告活动和“假设”场景非常有用,在这些场景中,面部/身份保留至关重要。通过指定基于现实的摄影外观(自然光、可信细节、无电影级调色)来锚定真实感,并锁定主体不可改变的部分。当可用时,更高的输入保真度有助于在较大的场景编辑中保持相似性。
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-1.5",
input_fidelity="high",
quality="high",
image=[
open("../../images/input_images/woman_in_museum.png", "rb"),
],
prompt=prompt
)
save_image(result, "scene.png")
输出图像:

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-1.5",
input_fidelity="high",
quality="high",
image=[
open("../../images/output_images/test_woman.png", "rb"),
open("../../images/output_images/test_woman_2.png", "rb"),
],
prompt=prompt
)
save_image(result, "test_woman_with_dog.png")
| 图像输入1 | 图像输入2 | 输出 |
|:------------:|:--------------:|:--------------:|
|
|
|
|
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-1.5",
image=[
open("../../images/input_images/kitchen.jpeg", "rb"),
],
prompt=prompt
)
save_image(result, "kitchen-chairs.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-1.5",
prompt=prompt,
)
save_image(result, "christmas_holiday_card_teddy.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-1.5",
prompt=prompt,
)
save_image(result, "christmas_collectible_toy_airplane.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-1.5",
prompt=prompt,
)
save_image(result, "childrens_book_illustration_1.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-1.5",
image=[
open("../../images/output_images/childrens_book_illustration_1.png", "rb"), # ← use image from step 1
],
prompt=prompt,
)
save_image(result, "childrens_book_illustration_2.png")
输出图像:

结论
在本笔记本中,我们演示了如何使用 gpt-image-1.5 构建高质量、可控的图像生成和编辑工作流,这些工作流在实际生产环境中经得起考验。本手册强调提示结构、显式约束和小步迭代修改是控制真实感、布局、文本准确性和身份保持的主要工具。我们涵盖了生成和编辑模式——从信息图、照片级真实感、UI 模型和徽标到翻译、风格迁移、虚拟试穿、合成和光照变化。在示例中,本手册反复强调了清晰区分哪些内容应改变、哪些内容必须保持不变的重要性,并在每次迭代中重申这些不变项以防止漂移。我们还强调了质量和输入保真度设置如何根据用例在延迟和视觉精度之间进行有意的权衡。这些示例共同构成了一个实用、可重复的指南,用于在生产图像工作流中部署 gpt-image-1.5。
常见问题
常见错误及排查:1) 提示词过于模糊导致输出不相关——应具体化主体、风格和细节,使用摄影术语或材质描述;2) 图像内文本拼写错误——将文本置于引号或全大写,并逐字母拼写关键单词;3) 编辑时身份漂移——在提示中明确列出不变项(如“保持面部、姿势、背景不变”),并在每次迭代中重复;4) 生成速度慢——设置 quality="low" 评估是否满足需求;5) 输出包含水印或多余元素——使用负面提示(如“无水印、无额外文本”);6) 多图像合成时元素位置错误——明确描述元素来源和放置位置(如“将图像2中的狗放在图像1中女士旁边”)。生产环境优化:使用异步调用或批量处理提升吞吐量;缓存常用提示词模板;对输出进行后处理(如背景移除、尺寸调整);监控 API 错误码并实现重试机制。
企业应用扩展
本教程可扩展至以下方向:1) 自动化工作流:结合 LangChain 或 Prefect 构建多步骤图像生成流水线,实现批量内容生产;2) 模型微调:基于 gpt-image-1.5 的输出进行风格迁移或领域适配,使用 LoRA 等技术降低微调成本;3) 质量评估:引入 FID、CLIP 分数等指标自动评估生成质量,建立回归测试体系;4) 多模态融合:将图像生成与文本生成(如 GPT-4)结合,实现从文案到视觉的端到端内容创作;5) 安全与合规:实现内容审核机制,过滤不当生成,确保符合平台政策。开发者可基于本教程的提示词模式,探索更多垂直场景(如医疗可视化、教育插图、游戏原画),并持续迭代优化提示词库。
总结
本教程面向有编程基础的开发者,系统讲解 gpt-image-1.5 图像生成与编辑模型的高级工程实践。内容涵盖提示词结构设计、生成与编辑场景(信息图、照片级真实感、Logo、UI 线框、风格迁移、虚拟试穿、对象移除等)、API 调用与代码实现、质量与延迟权衡、常见错误排查及生产环境优化。通过真实案例与可执行代码,帮助读者掌握可控图像生成的核心技巧,构建生产级视觉工作流。
- --
内容来源与验证
- 内容等级:PREMIUM_A
- 质量等级:S_CANDIDATE
- 难度:中级
- 验证等级:V1
- 原文作者:annikab-oai, msingh-openai, emreokcular
- 原文日期:2025-12-16
- 来源许可:MIT
- 来源版本:
bf2450f7620be7207701eba9461d46d96ea36323 - 查看原文
站内还有更多完整实战教程
加入会员,解锁全部教程、完整代码与持续更新内容。
加入会员