进阶 docs.ideogram.ai 2026-11-19 18:13:23 · 16 阅读

第53章 JSON 提示词(JSON Prompting)

JSON Prompting(JSON 提示词)

用 Ideogram 的 JSON 图像提示词来指定文本元素、色板和归一化边界框。本文介绍其格式、App 使用流程以及排版上的限制。可在 Markdown 中查看。

本页内容

Ideogram 4.5 和 4.0 既接受自然语言提示词,也接受结构化的 JSON 提示词,两个模型使用相同的 JSON 格式。Ideogram 4.0 就是用这种格式的字幕训练的,所以 JSON 提示词相当于用模型自己的"母语"和它沟通。

对大多数图像来说,自然语言已经够用。JSON 能提供自然语言给不了的控制力:

- 颜色控制:可以为整幅图设定最多 16 个 hex 颜色,每个元素最多 5 个。它们会强烈引导配色,但不会锁定每个像素。 - 布局:用边界框把任意元素放到画面中的指定位置。 - 文字排版:每段文字都是独立元素,拥有自己的位置和样式。 - 可复用的构图:保持描述和区域不变,只改选定的元素。不过不同次生成之间输出仍可能有差异。

何时使用 JSON

| 使用场景 | 推荐方式 | |---|---| | 快速构思、探索想法 | 自然语言 | | 扩写简短的想法 | 自然语言 + Magic Prompt | | 海报、品牌图形、标签、标识 | JSON | | 指定固定色板 | JSON | | 多张图保持相同布局 | JSON | | 对精确位置无要求的照片 | 自然语言 |

在 Image App 中使用 JSON 提示词

1. 在 Model picker 中明确选择 Ideogram 4.5 或 Ideogram 4.0。 2. 把 JSON 粘贴到 Prompt 框中,不要带 Markdown 代码围栏。 3. 如果不想让自己的提示词被扩写,在显示开关的地方关闭 Magic Prompt。 4. 在 App 控件中设置宽高比、分辨率、生成数量、质量和 seed。 5. 生成后检查文字、颜色和元素位置,再决定是否复用该提示词。

JSON 描述的是图像内容,它不能替代 App 的生成设置,也不是完整的 API 请求体。API 请求请参考 API Docs。

Magic Prompt 与 JSON 如何配合

你不必手写 JSON。在 Ideogram 4.5 和 4.0 上,Magic Prompt 会在生成前把纯文本提示词转换成结构化的 JSON 提示词:

- Magic Prompt 开启:它会改写并扩写你的想法,补充细节、风格和布局,然后生成 JSON。 - Magic Prompt 关闭:它会保留你的原话,只转换成结构化格式。 - 你粘贴的是有效 JSON:Ideogram 会按原样使用,并跳过 Magic Prompt——除非 Magic Prompt 是开启状态,那样它连你的 JSON 也会改写。

所以,如果手写了 JSON 并希望被原样使用,请关闭 Magic Prompt。

如果你的 JSON 不符合下述格式(例如缺少 high_level_description),Ideogram 会把它当作纯文本读取。Ideogram 4.5 的提示词框最多容纳 10,000 个字符,过长的 JSON 提示词可能丢失末尾的元素,因此请把最重要的元素放在前面。

Schema(结构定义)

JSON 提示词有三个顶层字段:

| 字段 | 是否必填 | 内容 | |---|---|---| | high_level_description | 必填 | 用一两句话概括整幅图 | | style_description | 可选 | 风格、光照、媒介和色板 | | compositional_deconstruction | 必填 | 背景和图中所有元素 |

high_level_description

如果整幅图只能说一句话,就说在这里。

```json {"high_level_description": "A medium-shot photograph of a barista pouring latte art in a cozy cafe."} ```

style_description

所有子字段都是可选的。拍摄照片用 photo,插画、绘画、3D、平面设计等用 art_style。模型是从分别使用其中之一的字幕中学到的,所以二选一即可。

| 字段 | 类型 | 内容 | |---|---|---| | aesthetics | string | 情绪和观感,例如 "moody, cinematic, desaturated" | | lighting | string | 例如 "golden hour, rim light, dramatic shadows" | | photo | string | 相机和镜头,例如 "35mm, f/1.4, bokeh"。与 art_style 二选一 | | medium | string | 自由文本,例如 "photograph"、"illustration"、"3D render"、"painting"、"graphic design" | | art_style | string | 非照片类作品,例如 "flat vector illustration, bold outlines"。与 photo 二选一 | | color_palette | 字符串列表 | 最多 16 个六位 hex 颜色,用于引导主色调,如 #FFD700 |

compositional_deconstruction

该字段包含 background(描述场景的字符串)和 elements(一个列表),两者都是必填。

每个元素要么是对象("obj"),要么是文字("text"):

| 类型 | 键的顺序 | |---|---| | "obj" | type, bbox(可选), desc, color_palette(可选) | | "text" | type, bbox(可选), text, desc, color_palette(可选) |

| 字段 | 类型 | 内容 | |---|---|---| | type | string | 对象和主体用 "obj",图内文字用 "text" | | bbox | 4 个整数的列表 | 位置,格式为 [y_min, x_min, y_max, x_max]。可选 | | desc | string | 元素的详细描述 | | text | string | 仅限文字元素:要渲染的精确文字 | | color_palette | 字符串列表 | 该元素最多 5 个六位 #RRGGBB 颜色。可选 |

注:Ideogram 会把每个块内的键按模型期望的顺序排列,所以你不必自己排序。但三个顶层字段请保持 schema 表中所示的顺序。

边界框

坐标在每个轴上取值 0 到 1000,[0, 0] 位于左上角,格式为 [y_min, x_min, y_max, x_max]。因此 [0, 0, 500, 1000] 覆盖图像上半部分,[250, 250, 750, 750] 位于正中央。省略 bbox 时,模型会自行安排元素位置。

要给标题区域留一点外边距,可以用 [100, 50, 300, 950],它表示从图像高度 10% 到 30%、宽度 5% 到 95% 的区域。注意纵坐标在前。这些都是相对坐标而非像素值,所以改变输出分辨率时不需要重新按像素换算。

每个轴上较小的坐标要写在前,取值保持在 0–1000 范围内。为每个文字块预留足够空间,并检查预期布局中是否有重叠。边界框只是引导生成的构图;如果位置和可编辑文字必须精确设定,请使用 Studio layers。

配色技巧

- 想确定整体基调,就把背景色也加进色板。 - 同时加入高光色和阴影色,可以更好地控制光照效果。 - 使用完整的六位 #RRGGBB 值(如 #FFD700),不要用三位简写。公开 schema 中 hex 字母大小写均可。

示例:不带边界框

建议先试试这个提示词:

```json { "high_level_description": "A lone lighthouse on a sea cliff under a glowing violet aurora at night.", "style_description": { "aesthetics": "dreamlike, majestic, quiet", "lighting": "aurora glow from above, warm beam from the lighthouse, deep blue shadows", "photo": "wide-angle, long exposure, crisp stars", "medium": "photograph", "color_palette": ["#2A1B5C", "#7B4FD6", "#3FD9B0", "#F5C46B", "#0B1026"] }, "compositional_deconstruction": { "background": "A night sky filled with swirling violet and teal aurora ribbons and scattered stars above a dark, calm sea.", "elements": [ { "type": "obj", "desc": "A white lighthouse with a red top standing on the edge of a rugged grassy cliff, its warm beam cutting across the sky." }, { "type": "obj", "desc": "Gentle waves breaking white against the rocks at the base of the cliff." } ] } } ```

设置:Ideogram 4.0,Magic Prompt 关闭,宽高比 1:2。

示例:带边界框的文字

当每行文字都需要出现在指定位置时,使用边界框:

```json { "high_level_description": "A bold event poster for a jazz night called 'Blue Note Sessions' at The Velvet Room, Saturday August 9th.", "style_description": { "aesthetics": "moody, retro, sophisticated, 1960s jazz club aesthetic", "lighting": "dramatic, deep shadows, warm spotlight glow", "medium": "graphic_design", "art_style": "vintage poster design, textured paper, bold typography, muted color palette with warm accents", "color_palette": ["#1A1A2E", "#16213E", "#E8C97A", "#D4A843", "#F5F0E8", "#8B4513"] }, "compositional_deconstruction": { "background": "Deep navy and near-black background with subtle aged paper texture and faint horizontal grain lines.", "elements": [ { "type": "obj", "bbox": [150, 200, 650, 800], "desc": "A silhouetted jazz trumpeter in side profile, mid-performance, instrument raised. Warm golden spotlight illuminates from above, casting dramatic shadows. Stylized, slightly abstract illustration style." }, { "type": "text", "bbox": [30, 50, 140, 950], "text": "BLUE NOTE SESSIONS", "desc": "Large bold all-caps serif headline in warm golden-yellow, spanning the full width near the top of the poster." }, { "type": "text", "bbox": [660, 100, 760, 900], "text": "Live jazz every Saturday night", "desc": "Medium-weight italic serif subheading in off-white, centered beneath the main title." }, { "type": "text", "bbox": [820, 200, 900, 800], "text": "THE VELVET ROOM", "desc": "Smaller all-caps sans-serif venue name in warm gold, centered near the bottom." }, { "type": "text", "bbox": [900, 300, 970, 700], "text": "SAT · AUGUST 9", "desc": "Small light-weight serif date text in off-white, near the bottom of the poster." } ] } } ```

设置:Ideogram 4.0,Magic Prompt 关闭,宽高比 1:2。

关于图内文字本身的措辞技巧,参见 Text in Images。

评论 (0)