OpenAI 官方指南:GPT Image 2.5 提示词工程解析(双模型架构与多图一致性实战)
OpenAI 官方指南:GPT Image 2.5 提示词工程解析
导读
OpenAI 发布了视觉生成模型 GPT Image 2.5 及配套的《Image Prompting Guide》。
相比上一代模型,GPT Image 2.5 重点改进了四项能力:双引号精准文字排版、多图参考角色解耦、局部图像编辑与透明通道抠图,以及跨镜头角色一致性。OpenAI 同步推出了
gpt-image-2.5-flare(高并发轻量版)与gpt-image-2.5-sunburst(高画质基础版)两款模型。本文基于 OpenAI 官方文档整理译注,涵盖双模型选型、API 参数约束、6 步迁移流程与 8 条提示词规则,并附 9 类单图场景、8 类多图编辑流程及 Python SDK 示例。
01|双模型对比与生产架构选型
在生产环境中,图像生成需要在延迟吞吐、推理成本与画质细节之间取得平衡。OpenAI 为 GPT Image 2.5 提供了两款不同定位的模型:
GPT Image 2.5 双模型对比与生产架构选型指南
1. 核心模型特性对比
| 对比项 | GPT Image 2.5 Flare(轻量速度版) | GPT Image 2.5 Sunburst(高画质基础版) |
|---|---|---|
| 定位与规模 | 小型轻量模型(Small Model) | 基础大模型(Base Model) |
| 响应延迟 | 低,适合实时交互与快速预览 | 较高,侧重细节还原与复杂推理 |
| 并发吞吐 | 吞吐量高,单次推理成本低 | 吞吐量受限,单次推理资源开销较高 |
| 长文本与指令遵循 | 适合标准指令与结构化模板 | 适合解析长句、嵌套空间关系与细微约束 |
| 文字排版精度 | 常见短标题表现稳定 | 支持长标语、特殊品牌名与密集文本排版 |
| 多图参考解耦 | 适合 1 张~2 张简单参考图合成 | 支持多张复杂参考图解耦(主体、服装、风格与光影) |
| 推荐适用场景 | 批量电商主图、草图实时预览、自动化资讯配图 | 商业产品摄影、印刷海报、复杂科学图表、品牌矢量 Logo |
2. 生产环境选型建议
- 先保质量,再测提速:如果旧版 GPT Image 2 已满足当前业务画质要求,优先接入
gpt-image-2.5-flare验证延迟与成本收益;如果业务包含复杂文字排版或精细构图,且旧版表现不佳,先接入gpt-image-2.5-sunburst建立画质基线。 - 使用真实业务负载测试:不要用外部通用 Benchmark 代替业务实测。响应时间与画质直接受 Prompt 复杂度、参考图分辨率和目标输出尺寸影响。
- 保持对比变量一致:首次跨模型对比时,保持 Prompt、参考图输入、分辨率及
quality参数完全一致,不要同时修改多项配置。
02|API 核心参数规格与分辨率约束
GPT Image 2.5 将控制指令与物理参数解耦:物理生成配置全部通过 API 参数传递,提示词只负责描述画面内容。
1. 核心 API 请求参数一览
| 参数名称 | 可选配置值 | 官方工程说明与推荐策略 |
|---|---|---|
model | gpt-image-2.5-flare / gpt-image-2.5-sunburst | 按延迟敏感度与画质要求选择对应模型 |
quality | auto(默认)、low、medium、high、xhigh、max | 从 medium 起步评估,仅当文字或细节不达标时再上调至 xhigh 或 max |
size | auto 或自定义分辨率 WIDTHxHEIGHT | 常用尺寸:1024x1024(方形)、1536x1024(横版 3:2)、1024x1536(竖版 2:3)、2048x1152(2K 16:9)、3840x2160(4K 16:9) |
background | auto、opaque(默认不透明)、transparent(透明) | 设为 transparent 时直接输出带 Alpha 通道的商品抠图或矢量图标 |
output_format | png / jpeg / webp | 透明底必须指定 png 或 webp;output_compression 仅对 JPEG 和 WebP 生效 |
2. 自定义分辨率的 5 项物理硬约束
传入自定义尺寸 WIDTHxHEIGHT 时,必须满足以下 5 项前置校验,否则 API 会直接返回参数校验错误:
- 单边上限:任意单边像素不得超过 3,840 像素。
- 16 像素对齐:宽和高都必须是 16 的整数倍(如 1024、1152、1536、2048 和 3840)。
- 长宽比上限:长边与短边之比不得超过 3:1。
- 总像素区间:整图总像素数必须在 655,360 像素~8,294,400 像素之间。
- 实验性尺寸:总像素数超过 3,686,400 像素(即高于
2560x1440)的高分辨率输出,当前版本属于实验性支持。
3. 透明通道(Alpha Channel)配置规范
设置 background="transparent" 时,需注意以下三点:
- 必须搭配
output_format="png"或output_format="webp"。 - 生成透明图时禁止启用
output_compression。 - 解码后的图像原生保留透明通道,能清晰呈现发丝、玻璃器皿、半透明投影和几何边缘。请在真实透明画布上核验 Alpha 通道边缘,不要叠在纯白背景上肉眼误判。
03|工作流迁移 6 步流程(Migration Blueprint)
从 GPT Image 1、1.5 或 2 迁移至 2.5 时,建议按以下 6 步推进:
| 1 | [1. 锁定业务基线] ──> [2. 选定首选候选] ──> [3. 完整要素核验] |
| 2 | │ |
| 3 | [6. 按业务线分流] <── [5. 单变量调优] <── [4. 延迟画质评估] |
- 第一步,锁定生产基线(Save a baseline):收集当前业务有代表性的 Prompt 与参考图,覆盖人脸、复杂商品、多字体排版和透明素材,记录旧模型的参数与输出结果。
- 第二步,选定候选模型(Choose the first candidate):旧版画质已达标的场景直接测
gpt-image-2.5-flare;高要求场景先测gpt-image-2.5-sunburst,保持 Prompt 与参数不变。 - 第三步,核验完整输出(Check the complete result):逐项检查指令遵循度、主体一致性、文字拼写和透明边缘毛刺,并对同一请求重复采样以评估输出稳定性。
- 第四步,对比延迟收益(Test latency gain):若 Sunburst 画质达标,用同一批输入测试 Flare。如果 Flare 同样达标且延迟与成本更低,切到 Flare;否则保留 Sunburst。
- 第五步,单变量调优(Tune one setting at a time):重写 Prompt 之前,先单独对比
quality档位。每次只改一个参数,便于定位问题原因。 - 第六步,按业务流灰度上线(Roll out by workflow):通过网关先切入 5% 流量,观察 P95 与 P99 延迟、错误率及单图成本,保留回滚开关。
04|提示词编写 8 条核心规则(Prompting Fundamentals)
OpenAI 总结了针对 GPT Image 2.5 的 8 条提示词编写规则:
GPT Image 2.5 提示词构建四层结构图
规则 1:明确定义最终产物(Define the result)
写清图像的用途与媒介类型,例如商业产品摄影、电商海报、技术架构图、矢量图标或分镜漫画,并指定构图比例与空间布局。复杂任务建议按四段式结构拆分:Scene(场景)、Subject(主体)、Details(细节)和 Constraints(约束)。
规则 2:选用易维护的格式(Choose a maintainable format)
短语列表、自然段落、JSON 键值对或分节标签的解析效果一致。优先选择团队工程师与设计师便于阅读、评审和版本管理的格式。
规则 3:描述肉眼可见的物理细节(Describe visible details)
删掉 hyperrealistic、8k、stunning 和 masterpiece 等空洞修饰词。直接写清三类细节:材质(如带折痕的粗帆布、哑光阳极氧化铝),光源方向(如右侧 45 度清晨柔光),以及成像质感(如 35 mm 胶片颗粒、浅景深)。
规则 4:写清人物景别与肢体动作(Specify people and actions)
指明取景范围(如 full body visible, feet included),并写清视线方向与手部动作(如 looking down at the open book、hands naturally gripping the handlebars),减少肢体畸变。
规则 5:用英文双引号锁定渲染文本(Specify exact text)
需要印在画面上的文字必须放进英文半角双引号中(如 "Yours to Create."),并写明渲染次数(如 Render the tagline exactly once),防止重复打印。同时说明字体风格与排版层级,末尾加上排除项 No extra text, no watermarks, no unrelated logos。
规则 6:拆分修改项与保留项(Separate changes from constraints)
在图像编辑任务中,先用 change only X 声明本次要改的内容,再逐条列出必须冻结不变的元素,包括面部五官、几何轮廓、色彩饱和度、光照方向、背景透视和原有文字。
规则 7:为多张参考图分配角色(Assign roles to references)
传入多张参考图时,在 Prompt 中按编号写清每张图的职责,例如 Image 1 is the subject、Image 2 is the artistic style、Image 3 is the background environment,并说明各元素的组合位置。
规则 8:跨轮次单变量迭代(Iterate deliberately)
多轮微调时,把上一轮的输出图直接作为下一轮的输入底图。每轮只提一项具体改动,同时重申上一轮的保留约束,防止多轮重绘后画面走样。
05|单图生成 9 类实战场景与官方 Prompt 模板
OpenAI 在官方文档中给出了 9 类常见场景的 Prompt 模板与参数配置,可直接复制使用。
场景 1:控制风格与真实光影(Control style and lighting)
目标:生成纪实胶片质感人像,消除涂抹感与假光影。
- 官方参数:
size="1024x1536",quality="medium" - 官方 Prompt 模板:
| 1 | Create a photorealistic candid photograph of an elderly sailor standing on a small fishing boat. |
| 2 | He has weathered skin with visible wrinkles, pores, and sun texture, and a few faded traditional sailor tattoos on his arms. |
| 3 | 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. |
| 4 | Soft coastal daylight, shallow depth of field, subtle film grain, natural color balance. |
| 5 | The image should feel honest and unposed, with real skin texture, worn materials, and everyday detail. No glamorization, no heavy retouching. |
场景 2:可视化信息图解与系统流程(Explain a process visually)
目标:生成带内部剖面与引线标签的设备工作流程图。
- 官方参数:
size="1024x1536",quality="medium" - 官方 Prompt 模板:
| 1 | Create a detailed Infographic of the functioning and flow of an automatic coffee machine like a Jura. |
| 2 | From bean basket, to grinding, to scale, water tank, boiler, etc. |
| 3 | I'd like to understand technically and visually the flow. |
场景 3:精准文本排版与品牌广告(Render exact text)
目标:在服饰海报中准确印出指定标语,避免拼写错误与重复字符。
- 官方参数:
size="1024x1536",quality="medium" - 官方 Prompt 模板:
| 1 | Give me a cool in culture ad / fashion shot for a brand called Thread. |
| 2 | It's a hip young street brand. The ad shows a group of friends hanging out together with the tagline "Yours to Create." |
| 3 | Make it feel like a polished campaign image for a youth streetwear audience: stylish, contemporary, energetic, and tasteful. |
| 4 | Use clean composition, strong color direction, natural poses, and premium fashion photography cues. |
| 5 | Render the tagline exactly once, clearly and legibly, integrated into the ad layout. |
| 6 | No extra text, no watermarks, no unrelated logos. |
场景 4:矢量风格透明底 Logo 设计(Design a reusable logo)
目标:设计扁平易缩放的品牌标志,直接输出带透明 Alpha 通道的 PNG 素材。
- 官方参数:
size="1024x1536",quality="medium",background="transparent",output_format="png",n=1 - 官方 Prompt 模板:
| 1 | Create an original, non-infringing logo for a company called Field & Flour, a local bakery. |
| 2 | The logo should feel warm, simple, and timeless. Use clean, vector-like shapes, a strong silhouette, and balanced negative space. |
| 3 | Favor simplicity over detail so it reads clearly at small and large sizes. Flat design, minimal strokes, no gradients unless essential. |
| 4 | Fully transparent background. Deliver a single centered logo with generous padding, clean alpha edges, and no solid backdrop, scenery, checkerboard, or watermark. |
场景 5:历史考据与时代场景还原(Use historical context)
目标:依据具体历史时间与地点,还原当时的服装样式与户外环境。
- 官方参数:
size="1024x1536",quality="medium" - 官方 Prompt 模板:
| 1 | Create a realistic outdoor crowd scene in Bethel, New York on August 16, 1969. |
| 2 | Photorealistic, period-accurate clothing, staging, and environment. |
场景 6:故事转化为多格分镜漫画(Turn a story into a comic strip)
目标:将四段剧情直接生成竖版四格漫画,保持分镜边框规整与主角外观一致。
- 官方参数:
size="1024x1536",quality="medium" - 官方 Prompt 模板:
| 1 | Create a short vertical comic-style reel with 4 panels. |
| 2 | Panel 1: The owner leaves through the front door, waving goodbye to their dog. |
| 3 | Panel 2: The dog waits alone in the living room, looking sad. |
| 4 | Panel 3: The dog discovers the remote control on the couch. |
| 5 | Panel 4: The dog turns on the TV and is excited. |
场景 7:UI 界面原型预览(Create an interface preview)
目标:生成生鲜市场移动端 App 界面原型,准确渲染指定商品名称列表。
- 官方参数:
size="1024x1536",quality="medium" - 官方 Prompt 模板:
| 1 | Create a realistic mobile app UI mockup for a local farmers market. |
| 2 | Show today’s market with a simple header and a short list of available products: |
| 3 | "Green Zebra Heirloom Tomato", "Strawberries", "Avocado", and "Tangerines". |
| 4 | Keep the interface clean, modern, and easy to scan. |
场景 8:科学与教育图解(Create scientific and educational visuals)
目标:生成高中生物细胞呼吸流程图解,准确标注专业术语与 ATP 产出数值。
- 官方参数:
size="1024x1536",quality="medium" - 官方 Prompt 模板:
| 1 | Create a simple biology diagram titled "Cellular Respiration at a Glance" for high school students. |
| 2 | Show the mitochondrion with clear, readable labels and simple arrows for the flow from Glucose to Glycolysis, the Krebs cycle, the electron transport chain, and ATP output. |
| 3 | Clean white background, high contrast, clean vector-like diagram style. |
| 4 | Accurate biological terminology. |
| 5 | Include a small callout box explaining that 36–38 ATP molecules are produced per glucose molecule. |
| 6 | No cluttered textures, no unnecessary decorative elements, no photorealistic styling. |
场景 9:商业演示幻灯片与图表(Build slides, diagrams, and charts)
目标:生成 B2B 软件公司 A 轮融资演示单页,包含三组核心指标、五年增长柱状图和三栏驱动因素。
- 官方参数:
size="1024x1536",quality="medium" - 官方 Prompt 模板:
| 1 | Create one pitch-deck slide titled **"Market Opportunity"** that feels like a real Series A fundraising presentation for a high-growth B2B software company. |
| 2 | |
| 3 | Include: |
| 4 | - A clear headline and a short subtitle explaining the shift. |
| 5 | - Three large, bold metrics with simple labels (for example: Total Addressable Market, Serviceable Addressable Market, and Projected Annual Growth Rate). |
| 6 | - A modern bar chart or clean horizontal comparison showing market growth over the next five years. |
| 7 | - A clean three-column layout below the chart highlighting key market drivers: customer demand, platform adoption, and regulatory tailwinds. |
| 8 | - A restrained color palette (deep slate, soft blue, warm amber accent), generous whitespace, and a high-end editorial tech aesthetic. |
| 9 | - A professional layout that looks built in Figma or Keynote, with consistent margins and balanced visual hierarchy. |
| 10 | |
| 11 | Make all text sharp, legible, correctly spelled, and positioned so that no labels overlap. |
06|多图参考输入与主体特征跨图解耦
早期文生图模型在传入多张参考图时,容易混淆人物外貌、服装材质和画风特征。GPT Image 2.5 原生支持多图输入与特征解耦(Feature Decoupling):
GPT Image 2.5 多图参考与特征解耦工作流
官方多图编辑 8 类工作流
1. 保留版式的图文翻译(Translate while preserving layout)
传入带英文标签的信息图,将文案翻译为西班牙语,同时冻结原有的插画结构、配色、字号层级与版面边距。
| 1 | Translate the text in the infographic to Spanish. Do not change any other aspect of the image. |
2. 视觉风格迁移(Transfer a visual style)
提取参考图的绘画媒介、调色板与笔触颗粒,直接应用到新主体上。
| 1 | Use the same style from the input image and generate a man riding a motorcycle on a white background. |
3. 锁定人物面部并换装(Preserve identity and change clothing)
冻结人物的面部五官与身形结构,仅根据多张单品参考图替换全身穿搭。
| 1 | Edit the image to dress the woman using the provided clothing images. Do not change her face, facial features, or body structure. |
4. 多图主体跨场景合成(Combine references)
从图 2 中提取宠物犬,放到图 1 女士身旁,并统一为图 1 的街景光影色调。
| 1 | Place the dog from the second image into the setting of image 1, right next to the woman, use the same style as image 1. |
5. 商品透明底抠图(Create a transparent product cutout)
将实拍商品从原背景中分离到纯透明画布上,保留瓶身材质反光与干净的 Alpha 边缘。
| 1 | Extract the product from the input image and isolate it on a fully transparent background. |
| 2 | Output a single centered product cutout with clean alpha edges, preserving all original colors, materials, textures, highlights, and fine details. |
| 3 | Ensure no background remnants, shadows, ground planes, or surrounding objects are visible. |
| 4 | Deliver a high-resolution PNG with true alpha transparency. |
6. 手绘线稿转写实照片(Turn a drawing into a realistic image)
传入黑白手绘草图,保持原有的构图比例与透视关系,渲染为自然风光照片。
| 1 | Turn this drawing into a photorealistic image. |
| 2 | Preserve the exact layout, proportions, and perspective of the original drawing. |
| 3 | Render natural textures, realistic lighting, and depth, while keeping all objects and elements faithful to the original composition. |
7. 局部物体消除与背景补全(Remove an object)
移除人物手中的花朵,保持其余画面不动,自动补全手指姿态与遮挡处的毛衣织纹。
| 1 | Remove the flower from man's hand. Do not change anything else. |
8. 人物置入动态新场景(Insert a person into a scene)
将参考图人物置入森林中躲避棕熊追赶的动态镜头,同步生成运动模糊与林间光影。
| 1 | Generate a highly realistic action scene where this person is running away from a large, realistic brown bear in a dense forest. |
| 2 | The person should look terrified, with natural motion blur to convey speed. |
| 3 | The bear is close behind, actively chasing with an aggressive stance. |
07|图像精准编辑与跨轮次防漂移迭代
实际业务出图通常需要多轮修改。OpenAI 给出了防止跨轮次画面走样的迭代流程:
GPT Image 2.5 图像编辑与跨轮次迭代流程
1. 单变量修改原则(The Single Variable Rule)
多轮微调时不要在一条请求里同时改三四个地方,否则容易触发全局重绘,导致原本满意的构图或五官走样。标准做法是:传入上一轮结果图,声明唯一的修改变量,并列出所有冻结保留项。
第一步:生成基准底图(Create starting image)
| 1 | Create a realistic billboard mockup of the shampoo on a highway scene during sunset. |
| 2 | Billboard text: "Nature's Secret Shampoo". |
| 3 | A billboard featuring the shampoo bottle prominently on a sunny road. |
| 4 | The surrounding environment should look natural, with highway signs, distant trees, and cars on the road. |
第二步:修改单一环境条件(Change one condition)
| 1 | Make it look like a winter evening with snowfall. |
2. 跨镜头角色一致性工作流(Character Consistency Workflow)
制作连续分镜、儿童绘本或品牌 IP 配图时,可以通过复用特征描述词并传入前序图来维持主角外貌一致。
第一步:建立角色基准图(Establish the character)
| 1 | Create a children’s book illustration introducing a main character. |
| 2 | |
| 3 | Subject: A playful 8-year-old girl named Maya. She has messy shoulder-length curly dark-brown hair, expressive hazel eyes, light freckles across her nose, and a missing upper right incisor that shows when she grins. She is wearing bright yellow rain overalls with rolled cuffs, a striped navy-and-white long-sleeve shirt underneath, and tomato-red rubber rain boots. |
| 4 | |
| 5 | Scene: Maya is jumping into a large rain puddle on a neighborhood sidewalk lined with colorful autumn trees. Leaves in shades of orange and gold float in the water. Her toy stuffed rabbit, "Barnaby"—a scruffy gray rabbit with one floppy ear—peeks out of her yellow backpack. |
| 6 | |
| 7 | Style & Mood: Whimsical storybook illustration style. Warm gouache and colored pencil texture with soft watercolor washes. Gentle natural morning light after a storm. Cheerful, adventurous, and full of childhood energy. Clean edges and expressive shapes suitable for a high-quality picture book. |
第二步:切换镜头继续叙事(Continue the story)
| 1 | Continue the children’s book story using the same character. |
| 2 | |
| 3 | Subject: The same 8-year-old girl, Maya, from the previous image. Keep her character design completely consistent: messy shoulder-length curly dark-brown hair, hazel eyes, freckled nose, missing upper right incisor, bright yellow rain overalls, striped navy-and-white shirt, and tomato-red rain boots. |
| 4 | |
| 5 | Action & Scene: A close-up shot of Maya sitting cross-legged on an old wooden bench inside a leafy greenhouse. She is carefully examining a bright-red ladybug resting on her outstretched finger with wide, curious eyes and a gentle smile. Her backpack sits beside her on the bench with the scruffy gray rabbit, Barnaby, still visible. Soft light filters through the rain-streaked glass ceiling above, with potted ferns, terracotta planters, and hanging vines surrounding her. |
| 6 | |
| 7 | Style & Mood: Maintain the same whimsical storybook illustration style, gouache and colored pencil texture, and warm color palette as the previous image. Quiet, intimate, and magical. |
3. 三组扩展实战工作流
扩展工作流 A:室内家具定向替换(Change furniture in a room)
保留相机机位、室内光照及墙地面材质,仅把白色餐椅替换为木质餐椅。
| 1 | In this room photo, replace ONLY the white chairs with chairs made of wood. |
| 2 | Preserve camera angle and lighting. |
| 3 | Maintain all existing textures and colors of the floor and walls. |
扩展工作流 B:节日贺卡插画与花体字排版(Design a holiday card)
生成雪夜小镇节日贺卡插画,顶部居中排印金色手写体 "Merry Christmas",下方排印小号副标题 "and a Happy New Year"。
| 1 | Create a Christmas holiday card illustration. |
| 2 | |
| 3 | Subject: A cozy village square covered in fresh snow at twilight. In the center is a grand evergreen Christmas tree decorated with glowing warm-white fairy lights, red and gold glass baubles, and a shining golden star on top. Townsfolk in colorful winter coats, wool scarves, and mittens are ice-skating on a small frozen pond nearby, with soft breath visible in the cold air. |
| 4 | |
| 5 | Setting: Quaint European-style half-timbered cottages with snow-laden rooftops and warm, amber light glowing from the mullioned windows line the square. A dusting of snow gently falls from a deep twilight sky tinted in shades of cobalt blue and violet, with a crescent moon peeking through the clouds. |
| 6 | |
| 7 | Style & Text: Nostalgic holiday greeting-card art style. Warm, painterly digital illustration with rich textures, soft glowing light, and a timeless, comforting holiday atmosphere. Centered at the top, render the greeting "Merry Christmas" in elegant, hand-lettered golden script. Centered below in smaller text, render "and a Happy New Year". |
| 8 | |
| 9 | Output: Clean composition framed nicely for a folded greeting card with balanced margins and high visual polish. |
扩展工作流 C:潮玩手办与开窗包装盒设计(Design collectible merchandise)
设计复古螺旋桨飞机潮玩 "AeroPup",包含透明亚克力开窗展示盒与盒面品牌印刷字样。
| 1 | Create a collectible action figure of a vintage-style toy propeller airplane with rounded wings, a friendly smiling front face on the engine cowl, and oversized landing gear wheels. |
| 2 | |
| 3 | Product Details: The plane is painted in matte retro teal and creamy off-white with cherry-red accents on the wingtips and propeller. Chunky, satisfying proportions designed as a collectible designer toy. |
| 4 | |
| 5 | Packaging: The toy is packaged inside a retro-inspired window display box with clear acetate on the front and sides, showing the toy securely held in place. The box has vintage-style typography and illustrations, with the product name "AeroPup" printed on the top and bottom panels. |
| 6 | |
| 7 | Presentation: Display the boxed collectible against a neutral warm-gray background with soft studio lighting and subtle product reflections underneath. Photorealistic product render, sharp focus, premium collectible packaging design. |
08|Python SDK 调用代码示例
以下示例基于 OpenAI 官方 Python SDK 编写,涵盖单图生成、透明底 PNG 导出与多图参考编辑:
| 1 | import os |
| 2 | import base64 |
| 3 | from pathlib import Path |
| 4 | from openai import OpenAI |
| 5 | |
| 6 | # 初始化 OpenAI 客户端 |
| 7 | client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY")) |
| 8 | |
| 9 | def generate_photorealistic_scene(): |
| 10 | # 示例 1:调用 Sunburst 模型生成纪实人像 |
| 11 | response = client.images.generate( |
| 12 | model="gpt-image-2.5-sunburst", |
| 13 | prompt=( |
| 14 | "Create a photorealistic candid photograph of an elderly sailor standing on a small fishing boat. " |
| 15 | "He has weathered skin with visible wrinkles, pores, and sun texture, adjusting a net. " |
| 16 | "Shot on 35mm film, 50mm lens, soft coastal daylight, shallow depth of field, subtle film grain. " |
| 17 | "No heavy retouching, authentic real-world texture." |
| 18 | ), |
| 19 | size="1536x1024", # 官方支持的标准横版尺寸 |
| 20 | quality="high", # 高画质档位 |
| 21 | n=1 |
| 22 | ) |
| 23 | |
| 24 | image_url = response.data[0].url |
| 25 | print(f"生成的图像 URL: {image_url}") |
| 26 | return image_url |
| 27 | |
| 28 | def generate_transparent_product_logo(): |
| 29 | # 示例 2:生成带透明通道 (Alpha Channel) 的矢量 Logo 并保存为 PNG |
| 30 | response = client.images.generate( |
| 31 | model="gpt-image-2.5-flare", # 使用轻量快速版 |
| 32 | prompt=( |
| 33 | "Create an original, non-infringing logo for a bakery called 'Field & Flour'. " |
| 34 | "Clean vector shapes, warm and simple, balanced negative space. " |
| 35 | "Fully transparent background, clean alpha edges, no background scenery, no watermarks." |
| 36 | ), |
| 37 | size="1024x1024", |
| 38 | quality="medium", |
| 39 | background="transparent", # 核心参数:启用透明背景 |
| 40 | output_format="png", # 必须为 png 或 webp |
| 41 | response_format="b64_json", # 获取 base64 字节流 |
| 42 | n=1 |
| 43 | ) |
| 44 | |
| 45 | # 将返回的二进制流保存为透明 PNG 文件 |
| 46 | image_data = base64.b64decode(response.data[0].b64_json) |
| 47 | with open("bakery_logo_transparent.png", "wb") as f: |
| 48 | f.write(image_data) |
| 49 | print("已保存带透明 Alpha 通道的 Logo: bakery_logo_transparent.png") |
| 50 | |
| 51 | def edit_with_multi_references(subject_img_path, style_img_path): |
| 52 | # 示例 3:多图参考输入(角色身份保持 + 视觉风格迁移) |
| 53 | with open(subject_img_path, "rb") as f_sub, open(style_img_path, "rb") as f_style: |
| 54 | response = client.images.edit( |
| 55 | model="gpt-image-2.5-sunburst", |
| 56 | image=[f_sub, f_style], # 传入多张参考图流 |
| 57 | prompt=( |
| 58 | "Image 1 is the subject character. Image 2 is the artistic visual style. " |
| 59 | "Render the character from image 1 in the exact brushwork, watercolor bleeding, " |
| 60 | "and color palette of image 2. " |
| 61 | "Keep the facial features, bone structure, and gaze direction of image 1 completely unchanged." |
| 62 | ), |
| 63 | size="1024x1024", |
| 64 | quality="high" |
| 65 | ) |
| 66 | return response.data[0].url |
| 67 | |
| 68 | if __name__ == "__main__": |
| 69 | print("启动 OpenAI GPT Image 2.5 调用示例...") |
| 70 | # generate_photorealistic_scene() |
09|生产上线前 5 项复核清单
将 GPT Image 2.5 接入生产环境前,请逐项核对以下 5 条工程约束:
- 按场景拆分模型路由:高频批量任务走
gpt-image-2.5-flare,复杂排版与精细修图走gpt-image-2.5-sunburst。 - 前置拦截非法尺寸:校验输入宽高满足 16 的整数倍、单边不超过 3,840 像素、长宽比不超过 3:1,且总像素在 65.5 万像素~829.4 万像素之间。
- 结构化编写提示词:按场景、主体、物理细节和排除约束四段组织内容,删掉无意义的抽象画质词。
- 锁定画面文字:需要渲染的文案统一加英文双引号,注明只渲染一次,并在末尾声明禁止多余文字与水印。
- 遵循单变量编辑:多轮修改时每次只改一个条件,显式列出需要冻结的面部、构图与背景特征。
版权声明与官方出处
文档来源与版权归属
- 官方文档出处:OpenAI Developer Documentation(developers.openai.com/api/docs/guides/image-prompting?model=gpt-image-2.5)
- 文档原始标题:《Image Prompting Guide (GPT Image 2.5)》
- 发布机构:OpenAI API Engineering & Research Team
- 整理译注:evaoo 架构技术团队
- 合规说明:本文遵照 OpenAI API 官方开发者条款整理译注,引用请注明官方文档链接与译注出处。
觉得本文有启发?一键复制标准引用摘要
自带原文归因链接与核心摘要,可直接粘贴至团队飞书/Slack 知识库、技术周报或大模型上下文。