一次投放很少只有一张图。同一支主视觉要在信息流当方图、在轮播当 4:5 竖版、在竖屏当 9:16,每个位置规格都不同。多数团队把主视觉导出成每个尺寸,再赌裁切落在合适的位置。这套流水线反过来:一张底图、几组合法尺寸、所有文字排在像素之外。

为什么一改尺寸就散架

素材散架不在生成,在两次交接。一是画幅换算:平台要 1080×1080,API 要边长是 16 的倍数,1080 直接被拒,最近的合法方图是 1088。二是文案叠加:价格、日期、免责声明都是精确字符串,模型画进像素就可能折行、掉字,这些错误在逐字核对前都看不出来。

GPT Image 2.5 的发布说明把编辑能力描述为「better at editing only what you’ve asked for, while keeping the rest of the details the same」。但改一个元素,不等于五个投放位用同一套字体。后者是模板的活,不是提示词的活。所以流水线分两段:生成在合法尺寸下产出一张留好安全区的底图,排版再把字叠上去。

API 真正接受的尺寸

换算方法:每条边向上取到 16 的倍数,比例不动。平台入库把 1088 缩回 1080,损失不到一个百分点,信息流下看不出来,但外侧 8 个像素可能被裁,主体留在中间 96% 内。

投放位平台规格发给 API 的尺寸为什么
信息流方图1080×10801088×10881080 不是 16 的倍数
竖版信息流1080×13501088×1360同上,比例保持 4:5
全屏竖屏1080×19201088×1920同上,比例保持 9:16
横版贴片1920×10801920×1088同上,比例保持 16:9

四条约束必须同时满足:最长边不超过 3840px,两边都是 16 的倍数,长短边比不超过 3:1,总像素在 655,360 到 8,294,400 之间;超过 2560×1440 属实验性。尺寸与比例说明 列了固定值,真正决定自定义值的是这四条。发请求前自己算一遍,报错不会说是哪条没过。

把文案从像素里拿出来

写提示词时,把自己当成给摄影师下 brief,而不是在排版:说清安全区在哪、主体可以被裁到哪里、图里一个字母都不要。

一张主视觉沿分发线扇出三个不同画幅的画面框,每个框内都有虚线安全区,框下各有一条独立文案条

上下两条带保持干净:竖屏留出下方八分之一,每张图下方留 14% 的文案带。提示词管不住边界,但能让这块区域色调平整,叠字时像刻意留白。标签出现字就重新生成,别拿画笔盖;修补痕迹审稿人一眼就看见。

Advertising photograph for a spring sale, one product on a plain seamless background, soft directional light from the left. The subject sits in the centre and stays fully inside the middle 76 percent, so the outer 12 percent on every side can be cropped away without losing the product. Keep the lower edge tonally flat and uncluttered. No text, no letters, no numbers, no logos, no watermarks, no signage, no packaging copy.

两个示例:方图与竖版

方图是必看的位置。这段 brief 四边各留 12%,更紧的裁切也不会切掉产品。

Overhead photograph of a pair of white running shoes on a warm grey background, centred, shot straight down. The shoes occupy the middle 76 percent of the frame; the outer 12 percent on every side is empty background. A soft shadow sits directly beneath them and touches nothing else. No props. No text, no letters, no logos, no watermarks.

交付前看三件事:阴影是否碰边、留白是否均匀、鞋面有无标识。再缩到 1080×1080,看 200px 缩略图里产品还认不认得出来。

竖屏反过来:平台在上下叠界面,主体压在中段,上下各留八分之一。

Vertical photograph of the same white running shoes on a warm grey background, seen from a low three-quarter angle. The shoes sit in the middle band of the frame, starting one eighth below the top edge and ending one eighth above the bottom edge. The top and bottom eighths are plain background with no detail at all. No text, no letters, no logos, no watermarks, no people.

先看上下两个八分之一,细节伸进去会被按钮盖住。竖版常跑第二遍,因为模型倾向于填满高度。

生成整套,再逐项检查

循环很短:主视觉加载一次,按每个投放位的合法尺寸发请求,用可预测的文件名落盘。

import base64
import pathlib

from openai import OpenAI

client = OpenAI()
campaign = "spring-sale"
hero = pathlib.Path("master/hero.png")
out = pathlib.Path("out")
out.mkdir(exist_ok=True)

# platform spec -> API-safe request: both sides must be multiples of 16
PLACEMENTS = {"square": "1088x1088", "portrait": "1088x1360", "story": "1088x1920"}
PROMPTS = {
    "square": "same hero, subject centred, 12 percent clear margin on all sides",
    "portrait": "same hero, subject in the upper two thirds, lower third left plain",
    "story": "same hero, subject in the middle band, top and bottom eighth plain",
}

for name, size in PLACEMENTS.items():
    with hero.open("rb") as handle:
        result = client.images.edit(
            model="gpt-image-2.5-flare",
            image=handle,
            prompt=PROMPTS[name],
            size=size,
            quality="high",
            output_format="webp",
            output_compression=88,
        )
    (out / f"{campaign}-{name}.webp").write_bytes(
        base64.b64decode(result.data[0].b64_json)
    )

批量跑用 gpt-image-2.5-flare:并发下更稳,延迟适合一次出十几张变体。需要更细的编辑控制就换 gpt-image-2.5-sunburst,更准但更慢。两个模型都不该写合规文案,原因见文字渲染的边界。

投放前的审核闸门

第二个脚本合成成品:校验几何、在图下方加一条文字带、输出 JPEG,文案始终不进像素。

from PIL import Image, ImageDraw

out = pathlib.Path("out")
copy_line = "Spring sale: up to 30 percent off"
SAFE = {"square": 0.12, "portrait": 0.10, "story": 0.08}

for name, margin in SAFE.items():
    path = out / f"{campaign}-{name}.webp"
    with Image.open(path) as img:
        w, h = img.size
        assert w % 16 == 0 and h % 16 == 0, (name, w, h)
        # the copy lives in its own band under the generated pixels
        sheet = Image.new("RGB", (w, h + round(h * 0.14)), "white")
        sheet.paste(img.convert("RGB"), (0, 0))
        draw = ImageDraw.Draw(sheet)
        draw.text((round(w * margin), h + 10), copy_line, fill="black")
        sheet.save(path.with_name(f"{campaign}-{name}-final.jpg"), quality=92)

脚本证明的是几何,不是判断。缩放和写 JPEG 时别弄丢 C2PA 元数据和不可见水印,平台日后靠它们识别生成文件;给客户看全尺寸默认用 high,差别见质量档位说明。剩下的得人来定。

  • 品牌一致性:每个投放位都是同一个产品、同一套颜色、同一套裁切逻辑。
  • 合规文案:法务确认过的那串字,落在文案带里,手机 100% 缩放仍然读得清。
  • moderation_blocked 是用户可纠正的错误,不要自动重试;同样的输入还会失败,重试只烧额度。
  • 每张图记一个 request id,和投放位名称写在一起,出问题才能从文件追回提示词。

常见问题

为什么 API 拒绝 1080?

1080 ÷ 16 = 67.5,边长过不了对齐规则,请求在生成像素前就被拒。1088 ÷ 16 = 68。向上取整发 1088,再让平台缩回 1080。

能不能直接让模型把文案画上去?

装饰性标题往往能看。价格、日期、免责声明不行:字母是当图形画的,某个字可能变形,只有人眼看得出来,最后错在要发出去的那版文件上。

每个尺寸都要重新生成一遍吗?

不用从头生成。一张底图,每个投放位做一次编辑,只改取景那句:方图居中、竖版放上三分之二、竖屏放中段。产品能一致,因为每次编辑都锚在底图上。

免责声明这类小字怎么办?

排到图下方的文案带,字号取该投放位真实宽度下仍可读的最小值。平台硬性要求文字在画面内,就在提示词里留一块平整区域再叠字,别让模型写。

一组素材本质是带一个变量的模板:底图。底图在合法尺寸下做对,文字留在你能控制的图层,下一个投放位只要一次编辑加一次缩放,不用重拍。