图像生成提示词的构成
主体、风格、媒介、光照、色彩搭配和构图元素。
图像生成提示词的构成 是 CoddyKit 上的免费 AI Prompt Engineering 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 AI Prompt Engineering 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 AI Prompt Engineering 课程共包含 4 节课。
作为配方的图像提示词
图像生成提示词是视觉效果的配方。这就像烹饪一样,素材的顺序和配比十分重要。缺少元素会产生普通的结果;加入错误元素则会导致出人意料的失败。掌握提示词的组成结构,才能获得可预测的创作控制力。
六个核心组成部分
每个优秀的图像提示词都包含六个组成部分:主体(是什么)、风格(呈现方式)、媒介(艺术形式)、光照(照明)、色彩调色板(色调)和构图(取景)。省略任何一个部分都会让模型自行猜测,通常会采用普通的默认设置。
# Anatomy of an image prompt
prompt_components = {
'subject': 'A lone lighthouse on a rocky coastline',
'style': 'dramatic, moody, cinematic',
'medium': 'oil painting',
'lighting': 'stormy overcast sky, waves crashing, dramatic side-lighting',
'color_palette': 'desaturated blues and grays with warm amber light from the lighthouse',
'composition': 'wide establishing shot, rule of thirds, lighthouse at left third'
}
# Assemble into a prompt string
full_prompt = (
'{subject}, {style}, {medium}, {lighting}, '
'{color_palette}, {composition}'
).format(**prompt_components)
print(full_prompt)
# A lone lighthouse on a rocky coastline, dramatic, moody, cinematic,
# oil painting, stormy overcast sky, waves crashing, dramatic side-lighting,
# desaturated blues and grays with warm amber light from the lighthouse,
# wide establishing shot, rule of thirds, lighthouse at left third主体:是什么
主体是最重要的组成部分,它告诉模型要描绘什么。请尽可能具体:包括物种、年龄、情绪、动作、环境和空间关系。
# Subject specificity comparison
# Weak subject:
weak = 'a person in a city'
# Strong subject (same concept, much more specific):
strong = (
'a young woman in her 30s, wearing a vintage 1960s trench coat, '
'standing at a rain-soaked street corner in Tokyo at night, '
'looking up at neon signs reflected in the puddles, '
'holding a dripping umbrella, expression of quiet wonder'
)
# The strong subject answers:
# WHO: young woman, 30s
# WHAT WEARING: 1960s trench coat
# WHERE: Tokyo street corner
# WHEN: night, raining
# WHAT DOING: standing, looking up
# EXPRESSION: quiet wonder
# KEY DETAIL: neon reflections in puddles, dripping umbrella
print('Weak:', weak)
print('Strong:', strong[:100], '...')风格:如何呈现
风格描述词告诉模型图像应采用的视觉语言和审美格调。它们可以参考艺术流派、特定艺术家、视觉媒介或抽象的审美特质。
style_examples = [
# Art movements
'impressionist', 'art nouveau', 'bauhaus', 'minimalist', 'surrealist',
# Artist references
'in the style of Monet', 'reminiscent of Hopper', 'inspired by Klimt',
# Visual media
'film noir', 'vaporwave aesthetic', 'cottagecore', 'brutalist',
# Quality descriptors
'highly detailed', 'cinematic', 'editorial photography style',
'concept art', 'matte painting', 'character design sheet',
# Mood
'ethereal', 'gritty', 'whimsical', 'melancholic', 'vibrant', 'serene'
]
# Combining styles creates unique aesthetics
combined_style = 'cyberpunk aesthetic meets art nouveau, highly detailed, dark ethereal'
print('Combined style:', combined_style)
# Warning: too many style directives create incoherence
too_many = 'impressionist, minimalist, surrealist, photorealistic, anime, baroque'
print('Too many (incoherent):', too_many)媒介:艺术形式
媒介定义实体或数字艺术形式。它会从根本上改变生成图像的纹理、线条质感和色调。常见媒介及其产生的效果如下:
medium_guide = {
# Traditional media
'oil painting': 'Rich, textured, classic look with visible brushwork',
'watercolor': 'Soft edges, translucent washes, paper texture visible',
'pencil sketch': 'Line art, cross-hatching, grayscale, raw feel',
'charcoal drawing': 'Soft, smudgy, high contrast, dramatic shadows',
'ink illustration': 'Bold lines, flat colors or crosshatching',
# Photography
'photorealistic': 'Looks like a real photograph',
'film photography': 'Grain, color shift, analog feel',
'macro photography': 'Extreme close-up, shallow depth of field',
'long exposure photography': 'Motion blur, light trails',
# Digital / 3D
'3D render': 'CGI quality, precise geometry',
'octane render': 'Photorealistic 3D with ray-tracing quality',
'Blender 3D': 'CGI aesthetic, often used with subdivision modeling',
'pixel art': 'Retro 8-bit or 16-bit style, visible pixels',
'vector illustration': 'Clean, flat, scalable design style'
}
for medium, description in list(medium_guide.items())[:5]:
print(f'{medium}: {description}')光照:塑造氛围
光照是视觉艺术中最有力的氛围塑造因素。同一主体在黄金时刻的阳光下,与在刺眼的审讯室灯光下,会呈现完全不同的效果。请掌握光照相关词汇。
lighting_vocabulary = {
# Time of day
'golden hour': 'Warm orange-yellow, long shadows, magic hour feel',
'blue hour': 'Cool blue twilight, soft diffused light',
'harsh midday': 'Hard shadows, washed-out, unflattering (usually avoided)',
'overcast': 'Soft even light, no shadows, good for portraits',
# Studio / artificial
'studio lighting': 'Controlled, professional, even illumination',
'Rembrandt lighting': 'Triangle of light on cheek, dramatic portrait technique',
'neon lighting': 'Colorful, urban, cyberpunk feel',
'candlelight': 'Warm, flickering, intimate',
# Dramatic
'chiaroscuro': 'Extreme light/dark contrast, Baroque dramatic style',
'volumetric lighting': 'God rays, light shafts through fog or dust',
'backlit / rim light': 'Subject outlined by light from behind, halo effect',
'bioluminescent': 'Glowing from within, alien or underwater feel'
}
example = 'volumetric lighting, golden hour, warm glow filtering through forest canopy'
print('Lighting example:', example)色彩调色板:情绪基调
色彩调色板控制图像的情绪基调和视觉统一性。您可以用描述性语言指定调色板,也可以参考艺术流派、电影或自然景观。
color_palette_examples = [
# Temperature-based
'warm earth tones: rust, ochre, sienna, cream',
'cool blues and silvers, icy palette',
'neutral gray monochrome with single red accent',
# Mood-based
'muted, desaturated, melancholic color grading',
'vibrant saturated colors, tropical energy',
'pastel soft colors, dreamlike softness',
# Reference-based
'Wes Anderson color palette: pastel pinks and greens',
'film noir: high contrast black and white with amber shadows',
'synthwave neon: pink, purple, cyan on dark backgrounds',
# Nature-based
'autumn forest: burnt orange, golden yellow, deep brown',
'arctic palette: white, pale blue, grey with deep navy accents',
]
# Color palettes can clash with lighting — ensure they work together
clash = 'vibrant tropical colors + film noir lighting' # incoherent
harmony = 'warm amber and ochre tones + golden hour lighting' # coherent
print('Harmonious combo:', harmony)构图:取景与焦点
构图指令告诉模型如何取景——应包含什么、应强调什么,以及应将各元素放置在哪里。借用摄影和电影摄影中的词汇通常很有效。
composition_vocabulary = {
# Camera distance
'extreme close-up': 'fills frame with a single detail (eye, hand, texture)',
'close-up': 'face or object fills most of frame',
'medium shot': 'waist to head, character-focused',
'wide shot': 'full body in environment context',
'establishing shot': 'landscape/environment, tiny or no character',
'aerial / bird\'s eye view': 'looking straight down',
'worm\'s eye view': 'looking straight up from below',
# Composition rules
'rule of thirds': 'subject at intersection of 1/3 lines',
'centered composition': 'symmetrical, formal, powerful',
'leading lines': 'lines guide eye toward subject',
'negative space': 'large empty area emphasizes subject',
'frame within frame': 'archway, window, or shape frames subject',
# Depth
'shallow depth of field': 'sharp subject, blurred background (bokeh)',
'deep focus': 'everything in sharp focus front to back'
}
print('Composition example: close-up portrait, rule of thirds, shallow depth of field, bokeh background')完整组装提示词
按照合理顺序组装全部六个组成部分,可以持续生成高质量的图像提示词。推荐顺序为:主体 → 媒介 → 风格 → 光照 → 色彩调色板 → 构图。
def build_image_prompt(
subject, medium, style, lighting, color_palette, composition,
quality_boost='highly detailed, 8K resolution'
):
parts = [
subject,
medium,
style,
lighting,
color_palette,
composition,
quality_boost
]
# Filter out None values and join
return ', '.join(p for p in parts if p)
# Example: Portrait
portrait = build_image_prompt(
subject='elderly Japanese fisherman mending nets at sunrise, weathered hands, peaceful expression',
medium='oil painting',
style='impressionist, highly detailed, classical technique',
lighting='golden hour sunrise, warm light from the left, soft shadows',
color_palette='warm ochres, golds, deep navy sea in background',
composition='medium shot, rule of thirds, subject right third, ocean left'
)
print(portrait)为多张图像保持一致性
生成一系列图像(角色设定表、分镜图)时,请使用基础提示词模板,并为不同图像中会变化的元素替换变量,以保持一致性。
BASE_CHARACTER_TEMPLATE = (
'{character_description}, '
'{action_description}, '
'oil painting, concept art style, '
'dramatic studio lighting, '
'muted jewel tones with gold accents, '
'close-up portrait, centered composition, '
'highly detailed, cinematic'
)
character = (
'a tall warrior woman with dark braided hair, emerald eyes, '
'wearing ornate silver plate armor with dragon motifs'
)
action_variants = [
'standing at attention, stoic expression, arms crossed',
'battle-ready, sword raised, fierce expression, mid-action',
'resting against a stone wall, exhausted but resolute, soft smile',
'close-up portrait, neutral expression, slight three-quarter view'
]
for action in action_variants:
prompt = BASE_CHARACTER_TEMPLATE.format(
character_description=character,
action_description=action
)
print(f'Generating: {action[:40]}...')
# call image API with prompt质量标记词
大多数图像模型都会响应质量标记词——这些术语用于表明所需的输出保真度。请有策略地使用它们来提升细节水平,同时不改变主体或风格。
quality_tokens = {
'high_detail': [
'highly detailed', 'intricate detail', 'ultra-detailed',
'8K resolution', '4K wallpaper quality'
],
'photorealism': [
'photorealistic', 'hyperrealistic', 'photographed by',
'DSLR photo', 'shot on 35mm film'
],
'professional_quality': [
'award-winning', 'professional photography', 'editorial quality',
'museum quality', 'masterpiece'
],
'rendering_quality': [
'octane render', 'unreal engine 5', 'ray tracing',
'subsurface scattering', 'global illumination'
]
}
# Best practice: add 2-3 quality tokens at the end of the prompt
quality_suffix = 'highly detailed, cinematic, 8K resolution'
print('Add to end of any prompt:', quality_suffix)
# Warning: do not overload with quality tokens — they dilute each other
too_many_quality = 'masterpiece, best quality, ultra-detailed, perfect, amazing, award-winning'
print('Over-specified (less effective):', too_many_quality[:60])快速检查
图像生成提示词中的哪个组成部分最直接地控制图像的情绪氛围?
图像提示词结构总结
构建良好的图像提示词包含六个相互协调的组成部分:
- 主体:WHO 和 WHAT——最重要的组成部分;应描述得非常具体
- 风格:审美格调、艺术流派或艺术家参考
- 媒介:艺术形式(油画、写实照片、三维渲染、像素艺术)
- 光照:塑造氛围的照明(黄金时刻、明暗对照法、霓虹灯)
- 色彩调色板:情绪温度(温暖的大地色、冷峻的低饱和色、霓虹色)
- 构图:取景(特写、三分法、建立镜头)
最后添加 2—3 个质量标记词。使用模板来保持多图系列的一致性。
常见问题解答
「图像生成提示词的构成」课时是免费的吗?
是的 — 「图像生成提示词的构成」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 AI Prompt Engineering 课程的其余内容,请升级到 CoddyKit PRO。 AI Prompt Engineering 课程共包含 4 节课。
「图像生成提示词的构成」这节课中我会学到什么?
主体、风格、媒介、光照、色彩搭配和构图元素。 你通过在浏览器中直接运行的动手代码来练习 AI Prompt Engineering,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 AI Prompt Engineering 需要有经验吗?
无需任何先前经验。CoddyKit 上的 AI Prompt Engineering 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。
「图像生成提示词的构成」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 AI Prompt Engineering 课中编写并运行代码吗?
能。每节 AI Prompt Engineering 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。