ComfyUI 有时会被称为节点式编程,但最基本的结构其实很简单:把模型和提示词输入 KSampler,然后输出图像。
不过,有时也会想构建稍微复杂一点的流程。
- 输入图像较小时,插入放大处理。
- 分析图像,如果手部可能崩坏,就加入后处理。
- 如果提示词中包含特定文字,就切换到另一种模型或设置。
- ...
这种“根据条件改变处理”的机制,在编程中叫做条件分支。ComfyUI 中也有一些基本节点,可以实现接近条件分支的处理。
条件分支的基本

{
"id": "29ed44dd-6fe2-456a-bd1a-461f34951fde",
"revision": 0,
"last_node_id": 8,
"last_link_id": 8,
"nodes": [
{
"id": 3,
"type": "LoadImage",
"pos": [
2748.9669779761944,
1624.9274767201969
],
"size": [
226.7833983976825,
326
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
3
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"B.png",
"image"
]
},
{
"id": 2,
"type": "LoadImage",
"pos": [
2492.7754310784335,
1498.5904319414708
],
"size": [
226.7833983976825,
326
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
1
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"A.png",
"image"
]
},
{
"id": 8,
"type": "PrimitiveBoolean",
"pos": [
2748.769003945466,
2005.3149857773456
],
"size": [
230.67001742550065,
58
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
8
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveBoolean"
},
"widgets_values": [
true
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 4,
"type": "PreviewImage",
"pos": [
3344.4342364224844,
1498.5904319414708
],
"size": [
304.55743368775256,
332.8579683361372
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 4
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewImage"
},
"widgets_values": []
},
{
"id": 1,
"type": "ComfySwitchNode",
"pos": [
3040.914082203413,
1498.5904319414708
],
"size": [
270,
78
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "on_false",
"type": "IMAGE",
"link": 1
},
{
"name": "on_true",
"type": "IMAGE",
"link": 3
},
{
"name": "switch",
"type": "BOOLEAN",
"widget": {
"name": "switch"
},
"link": 8
}
],
"outputs": [
{
"name": "output",
"type": "IMAGE",
"links": [
4
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfySwitchNode"
},
"widgets_values": [
false
],
"color": "#232",
"bgcolor": "#353"
}
],
"links": [
[
1,
2,
0,
1,
0,
"IMAGE"
],
[
3,
3,
0,
1,
1,
"IMAGE"
],
[
4,
1,
0,
4,
0,
"IMAGE"
],
[
8,
8,
0,
1,
2,
"BOOLEAN"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.9229599817706482,
"offset": [
-2156.9237407065307,
-1178.4599104270771
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
用 Switch 切换
条件分支的基础是 Switch 节点。
它会在两个输入中切换要输出哪一个。
这样就可以做到:条件满足时输出 a,不满足时输出 b。
Switch 需要传入 Boolean
在 Switch 中,用来决定两个输入中输出哪一个的值,就是 Boolean。
Boolean 是一种很简单的类型,只能是 true 或 false(0 or 1)。可以理解成一个开关。
当然,也可以手动点来切换,但这样就不太有意思了。
用程序式的方式切换处理,本质上就是在讨论:这个 Boolean 要怎么做出来。
创建 Boolean 的方法
在编程中,创建 Boolean 的方法有很多。这里先看几个 ComfyUI 核心节点中比较通用的方法。
Math Expression
这个节点在 简单计算 中也用过。使用它可以比较数值,并创建 Boolean。
例如,可以这样写。

{
"id": "ff9a0a9c-3ced-4326-962a-7af275c3f71d",
"revision": 0,
"last_node_id": 3,
"last_link_id": 2,
"nodes": [
{
"id": 3,
"type": "PreviewAny",
"pos": [
3324.4682790386732,
1536.2539712098414
],
"size": [
210,
165.81084525752772
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 2
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
]
},
{
"id": 2,
"type": "PrimitiveInt",
"pos": [
2692.0190372490806,
1536.2539712098414
],
"size": [
246.3932026778166,
82
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "INT",
"type": "INT",
"links": [
1
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveInt"
},
"widgets_values": [
20,
"fixed"
]
},
{
"id": 1,
"type": "ComfyMathExpression",
"pos": [
2981.095936608758,
1536.2539712098414
],
"size": [
300.68864574805593,
165.81084525752772
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [
{
"label": "a",
"name": "values.a",
"type": "FLOAT,INT,BOOLEAN",
"link": 1
},
{
"label": "b",
"name": "values.b",
"shape": 7,
"type": "FLOAT,INT,BOOLEAN",
"link": null
}
],
"outputs": [
{
"name": "FLOAT",
"type": "FLOAT",
"links": null
},
{
"name": "INT",
"type": "INT",
"links": null
},
{
"name": "BOOL",
"type": "BOOLEAN",
"links": [
2
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyMathExpression"
},
"widgets_values": [
"a == 20"
],
"color": "#232",
"bgcolor": "#353"
}
],
"links": [
[
1,
2,
0,
1,
0,
"INT"
],
[
2,
1,
2,
3,
0,
"BOOLEAN"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1.2284597357367328,
"offset": [
-2415.4416212964616,
-1188.9216918748982
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
a == 20
把输入 18 或 20 等数值的 int 节点连接到 a。
可以看到,只有当值为 20,也就是设定的值时,才会显示 true。
也可以使用更多数值和变量。
0 < a <= b * 100
这个表达式中,当 a 大于 0,并且小于等于 b * 100 时,会得到 true。
还可以使用下面这些比较运算符。
a == b # 相等
a != b # 不相等
a > b # a 大于 b
a >= b # a 大于等于 b
a < b # a 小于 b
a <= b # a 小于等于 b
Compare Text
要从文字创建 Boolean,可以使用 Compare Text 节点。
功能非常简单:比较两个 string,并将结果作为 Boolean 输出。
例如,可以判断输入文本是否等于 Hello,是否以 Hello 开头,或是否以 Hello 结尾。

{
"id": "1db6b4f2-1dca-4383-93dc-766f6750bfc2",
"revision": 0,
"last_node_id": 6,
"last_link_id": 5,
"nodes": [
{
"id": 5,
"type": "PrimitiveString",
"pos": [
2668.412239926897,
1536.2539712098414
],
"size": [
270,
58
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
3
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveString"
},
"widgets_values": [
"Hello World"
]
},
{
"id": 6,
"type": "PrimitiveString",
"pos": [
2668.412239926897,
1662.1432549853873
],
"size": [
270,
58
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
4
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveString"
},
"widgets_values": [
"Hello"
]
},
{
"id": 3,
"type": "PreviewAny",
"pos": [
3324.4682790386732,
1536.2539712098414
],
"size": [
210,
190
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 5
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
]
},
{
"id": 4,
"type": "StringCompare",
"pos": [
2986.3871153189016,
1536.2539712098414
],
"size": [
290.1062883277673,
190
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "string_a",
"type": "STRING",
"widget": {
"name": "string_a"
},
"link": 3
},
{
"name": "string_b",
"type": "STRING",
"widget": {
"name": "string_b"
},
"link": 4
}
],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
5
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "StringCompare"
},
"widgets_values": [
"",
"",
"Starts With",
true
],
"color": "#232",
"bgcolor": "#353"
}
],
"links": [
[
3,
5,
0,
4,
0,
"STRING"
],
[
4,
6,
0,
4,
1,
"STRING"
],
[
5,
4,
0,
3,
0,
"BOOLEAN"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1.2284597357367328,
"offset": [
-2371.487836752543,
-1201.4036934558803
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
它会比较 string_a 和 string_b,条件满足时输出 true,不满足时输出 false。
modeStarts With:string_a是否以string_b开头Ends With:string_a是否以string_b结尾Equal:string_a和string_b是否相同
- 将
case_sensitive设为true时,会区分大小写。
MLLM
稍微更丰富一点的方法,是使用 MLLM 来创建 Boolean。
前面说过,Boolean 可以用 true / false 表示,但其实也可以用数字 1 / 0 表示。
也就是说,可以对 MLLM 说:如果是〇〇,就输出 1;否则输出 0,然后把这个结果转换成 Boolean。

{
"id": "0bba12a8-d546-4b15-a099-13cb9870e6e3",
"revision": 0,
"last_node_id": 8,
"last_link_id": 10,
"nodes": [
{
"id": 1,
"type": "TextGenerate",
"pos": [
2903.298553740228,
1430.3770893064775
],
"size": [
400,
412
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 1
},
{
"name": "image",
"shape": 7,
"type": "IMAGE",
"link": 5
},
{
"name": "video",
"shape": 7,
"type": "IMAGE",
"link": null
},
{
"name": "audio",
"shape": 7,
"type": "AUDIO",
"link": null
}
],
"outputs": [
{
"name": "generated_text",
"type": "STRING",
"links": [
4,
8
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "TextGenerate"
},
"widgets_values": [
"この画像に女性が映っていれば 1 を、そうでなければ 0 を出力してください。",
256,
"on",
0.7,
64,
0.95,
0.05,
1.05,
0,
0,
false,
true
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 2,
"type": "CLIPLoader",
"pos": [
2579.1308760374027,
1430.3770893064775
],
"size": [
280.8288815898386,
106
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "CLIP",
"type": "CLIP",
"links": [
1
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "CLIPLoader"
},
"widgets_values": [
"qwen3.5_4b_bf16.safetensors",
"stable_diffusion",
"default"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 5,
"type": "ComfyNumberConvert",
"pos": [
3330.6504958704527,
1430.3770893064775
],
"size": [
178.0101231973421,
46
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"label": "value",
"name": "value",
"type": "INT,FLOAT,STRING,BOOLEAN",
"link": 4
}
],
"outputs": [
{
"name": "FLOAT",
"type": "FLOAT",
"links": null
},
{
"name": "INT",
"type": "INT",
"links": [
9
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyNumberConvert"
},
"widgets_values": [],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 7,
"type": "ComfyMathExpression",
"pos": [
3536.0125611980197,
1430.3770893064775
],
"size": [
235.5094643140137,
143.8565237478972
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"label": "a",
"name": "values.a",
"type": "FLOAT,INT,BOOLEAN",
"link": 9
},
{
"label": "b",
"name": "values.b",
"shape": 7,
"type": "FLOAT,INT,BOOLEAN",
"link": null
}
],
"outputs": [
{
"name": "FLOAT",
"type": "FLOAT",
"links": null
},
{
"name": "INT",
"type": "INT",
"links": null
},
{
"name": "BOOL",
"type": "BOOLEAN",
"links": [
10
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyMathExpression"
},
"widgets_values": [
"a"
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 8,
"type": "PreviewAny",
"pos": [
3798.8739676422583,
1430.3770893064775
],
"size": [
210,
112
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 10
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
]
},
{
"id": 4,
"type": "PreviewAny",
"pos": [
3330.6504958704527,
1646.5910947583602
],
"size": [
210,
112
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 8
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
]
},
{
"id": 3,
"type": "LoadImage",
"pos": [
2579.1308760374027,
1605.568342010362
],
"size": [
280.8288815898386,
403.7872325736837
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
5
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"0005_amodal_rebuild001_0005.png",
"image"
]
}
],
"links": [
[
1,
2,
0,
1,
0,
"CLIP"
],
[
4,
1,
0,
5,
0,
"STRING"
],
[
5,
3,
0,
1,
1,
"IMAGE"
],
[
8,
1,
0,
4,
0,
"STRING"
],
[
9,
5,
1,
7,
0,
"INT"
],
[
10,
7,
2,
8,
0,
"BOOLEAN"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.9229599817706495,
"offset": [
-2247.520386763948,
-1115.6613995536602
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
- 这里使用
TextGenerate节点,并使用 Qwen 3.5 4B。 - 稍微有点绕,但 MLLM 的输出是文本,也就是
string,所以先转换为int,再转换为Boolean。
相比单纯的数值或文本比较,使用 MLLM 可以做更灵活、更复杂的判断。
- 这张图里有几个人?
- 这个提示词更适合动漫模型,还是写实模型?
- 输出图像的质量好还是差?
组合多个条件
有时会想组合多个条件,例如“图像高度在 1000px 以上 并且 宽度小于 500px”。
这种场景会用到 逻辑运算符。
AND / OR / NOT
逻辑运算符有三种:AND / OR / NOT。
当有多个 Boolean 输入时,会根据它们的组合输出 true 或 false。

{
"id": "29b7b79f-f765-42d3-bf97-c0310f2e4ab1",
"revision": 0,
"last_node_id": 8,
"last_link_id": 8,
"nodes": [
{
"id": 1,
"type": "ComfyAndNode",
"pos": [
3243.655451593356,
1424.6992835911767
],
"size": [
180.474609375,
86
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"label": "value0",
"name": "values.value0",
"type": "*",
"link": 1
},
{
"label": "value1",
"name": "values.value1",
"shape": 7,
"type": "*",
"link": 2
},
{
"label": "value2",
"name": "values.value2",
"shape": 7,
"type": "*",
"link": null
}
],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
6
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyAndNode"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 2,
"type": "ComfyOrNode",
"pos": [
3243.655451593356,
1600.9782195634316
],
"size": [
180.474609375,
86
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"label": "value0",
"name": "values.value0",
"type": "*",
"link": 3
},
{
"label": "value1",
"name": "values.value1",
"shape": 7,
"type": "*",
"link": 4
},
{
"label": "value2",
"name": "values.value2",
"shape": 7,
"type": "*",
"link": null
}
],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
7
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyOrNode"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 3,
"type": "ComfyNotNode",
"pos": [
3243.655451593356,
1777.2571555356867
],
"size": [
180.474609375,
26
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "value",
"type": "*",
"link": 5
}
],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
8
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyNotNode"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 4,
"type": "PrimitiveBoolean",
"pos": [
2849.5866872595443,
1533.0468610425542
],
"size": [
270,
58
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
1,
3
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveBoolean"
},
"widgets_values": [
true
],
"color": "#2a363b",
"bgcolor": "#3f5159"
},
{
"id": 5,
"type": "PrimitiveBoolean",
"pos": [
2849.569497039055,
1656.9267808516133
],
"size": [
270,
58
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
2,
4,
5
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveBoolean"
},
"widgets_values": [
false
],
"color": "#322",
"bgcolor": "#533"
},
{
"id": 6,
"type": "PreviewAny",
"pos": [
3480.0359374991986,
1424.6992835911767
],
"size": [
241.08104976588402,
112
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 6
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
],
"color": "#322",
"bgcolor": "#533"
},
{
"id": 7,
"type": "PreviewAny",
"pos": [
3480.0359374991986,
1600.9782195634316
],
"size": [
241.08104976588402,
112
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 7
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
],
"color": "#2a363b",
"bgcolor": "#3f5159"
},
{
"id": 8,
"type": "PreviewAny",
"pos": [
3480.0359374991986,
1777.2571555356867
],
"size": [
241.08104976588402,
112
],
"flags": {},
"order": 7,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 8
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
],
"color": "#2a363b",
"bgcolor": "#3f5159"
}
],
"links": [
[
1,
4,
0,
1,
0,
"BOOLEAN"
],
[
2,
5,
0,
1,
1,
"BOOLEAN"
],
[
3,
4,
0,
2,
0,
"BOOLEAN"
],
[
4,
5,
0,
2,
1,
"BOOLEAN"
],
[
5,
5,
0,
3,
0,
"BOOLEAN"
],
[
6,
1,
0,
6,
0,
"BOOLEAN"
],
[
7,
2,
0,
7,
0,
"BOOLEAN"
],
[
8,
3,
0,
8,
0,
"BOOLEAN"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1.1167815779424861,
"offset": [
-2610.9052853223634,
-1235.8307818001963
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
- AND: 只有全部为
true时才输出true - OR: 只要有一个为
true,就输出true - NOT: 反转
true和false
当然,这些也可以组合使用。
例如,将 AND 和 NOT 组合起来,就可以在两个输入都为 true 时输出 false。
不用想得太复杂。实际连起来看看它们怎么动就可以了。
实践例
如果图像是竖图,就旋转 90 度

{
"id": "b44355d7-ed6f-45da-8b10-a323c1253081",
"revision": 0,
"last_node_id": 11,
"last_link_id": 10,
"nodes": [
{
"id": 1,
"type": "LoadImage",
"pos": [
2804.885198733637,
1394.2279939324023
],
"size": [
279.21710715197923,
387.42527994692887
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
1,
7,
8
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"0054_amodal_rebuild001_0055 (1).png",
"image"
]
},
{
"id": 3,
"type": "ComfyMathExpression",
"pos": [
3358.744771432823,
1611.8942365428447
],
"size": [
293.4438010526278,
158.81020881025938
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"label": "a",
"name": "values.a",
"type": "FLOAT,INT,BOOLEAN",
"link": 2
},
{
"label": "b",
"name": "values.b",
"shape": 7,
"type": "FLOAT,INT,BOOLEAN",
"link": 3
},
{
"label": "c",
"name": "values.c",
"shape": 7,
"type": "FLOAT,INT,BOOLEAN",
"link": null
}
],
"outputs": [
{
"name": "FLOAT",
"type": "FLOAT",
"links": null
},
{
"name": "INT",
"type": "INT",
"links": null
},
{
"name": "BOOL",
"type": "BOOLEAN",
"links": [
4
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyMathExpression"
},
"widgets_values": [
"a < b"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 4,
"type": "ComfySwitchNode",
"pos": [
3673.9612274799,
1394.2279939324023
],
"size": [
230.99505860380214,
78
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "on_false",
"type": "IMAGE",
"link": 8
},
{
"name": "on_true",
"type": "IMAGE",
"link": 9
},
{
"name": "switch",
"type": "BOOLEAN",
"widget": {
"name": "switch"
},
"link": 4
}
],
"outputs": [
{
"name": "output",
"type": "IMAGE",
"links": [
10
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfySwitchNode"
},
"widgets_values": [
false
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 11,
"type": "PreviewImage",
"pos": [
3936.81673188957,
1394.2279939324023
],
"size": [
367.53720929434166,
315.2072473810899
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 10
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewImage"
},
"widgets_values": []
},
{
"id": 2,
"type": "GetImageSize",
"pos": [
3121.0626802023608,
1609.3754605618176
],
"size": [
210,
136
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 1
}
],
"outputs": [
{
"name": "width",
"type": "INT",
"links": [
2
]
},
{
"name": "height",
"type": "INT",
"links": [
3
]
},
{
"name": "batch_size",
"type": "INT",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "GetImageSize"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 10,
"type": "ImageRotate",
"pos": [
3358.744771432823,
1480.0859384220487
],
"size": [
226.0425153311071,
58
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 7
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
9
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ImageRotate"
},
"widgets_values": [
"90 degrees"
],
"color": "#323",
"bgcolor": "#535"
}
],
"links": [
[
1,
1,
0,
2,
0,
"IMAGE"
],
[
2,
2,
0,
3,
0,
"INT"
],
[
3,
2,
1,
3,
1,
"INT"
],
[
4,
3,
2,
4,
2,
"BOOLEAN"
],
[
7,
1,
0,
10,
0,
"IMAGE"
],
[
8,
1,
0,
4,
0,
"IMAGE"
],
[
9,
10,
0,
4,
1,
"IMAGE"
],
[
10,
4,
0,
11,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.7627768444385532,
"offset": [
-2311.7396288934533,
-909.3072739208028
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
- 使用
Get Image Size获取图像尺寸 - 图像为竖图时,
width < height会变成true - 当结果为
true时,输出用Rotate Image旋转后的输入图像
如果画面中有女性,就改成男性
如果画面中有女性,就将其改成男性。否则,删除所有人物。

{
"id": "e47d064a-cb92-4da7-b92b-be9f1ddd26f5",
"revision": 0,
"last_node_id": 70,
"last_link_id": 103,
"nodes": [
{
"id": 8,
"type": "VAEDecode",
"pos": [
1615.039087801503,
160.40068341159756
],
"size": [
161.111083984375,
46
],
"flags": {},
"order": 21,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": 52
},
{
"name": "vae",
"type": "VAE",
"link": 62
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"slot_index": 0,
"links": [
65
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.39",
"Node name for S&R": "VAEDecode"
},
"widgets_values": []
},
{
"id": 43,
"type": "VAELoader",
"pos": [
517.231573621917,
656.7863480776692
],
"size": [
269.8313103058076,
58
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "VAE",
"type": "VAE",
"links": [
62,
76
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.39",
"Node name for S&R": "VAELoader"
},
"widgets_values": [
"flux2-vae.safetensors"
]
},
{
"id": 54,
"type": "ResizeImageMaskNode",
"pos": [
514.4495897676222,
484.74016932307575
],
"size": [
270,
106
],
"flags": {},
"order": 13,
"mode": 0,
"inputs": [
{
"name": "input",
"type": "IMAGE,MASK",
"link": 82
}
],
"outputs": [
{
"name": "resized",
"type": "IMAGE",
"links": [
80
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.9.2",
"Node name for S&R": "ResizeImageMaskNode"
},
"widgets_values": [
"scale to multiple",
16,
"nearest-exact"
]
},
{
"id": 52,
"type": "VAEEncode",
"pos": [
821.9650317382822,
484.74016932307575
],
"size": [
162,
46
],
"flags": {},
"order": 15,
"mode": 0,
"inputs": [
{
"name": "pixels",
"type": "IMAGE",
"link": 80
},
{
"name": "vae",
"type": "VAE",
"link": 76
}
],
"outputs": [
{
"name": "LATENT",
"type": "LATENT",
"links": [
74,
75
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.9.2",
"Node name for S&R": "VAEEncode"
},
"widgets_values": []
},
{
"id": 33,
"type": "CLIPTextEncode",
"pos": [
558.700000000001,
387.24938745307793
],
"size": [
425.2650317382812,
122.99611236572264
],
"flags": {
"collapsed": true
},
"order": 8,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 64
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"slot_index": 0,
"links": [
86
]
}
],
"title": "CLIP Text Encode (Negative Prompt)",
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.39",
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
""
]
},
{
"id": 57,
"type": "CLIPLoader",
"pos": [
-1046.5432691773194,
203.48293731896845
],
"size": [
280.8288815898386,
106
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "CLIP",
"type": "CLIP",
"links": [
87
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "CLIPLoader"
},
"widgets_values": [
"qwen3.5_4b_bf16.safetensors",
"stable_diffusion",
"default"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 58,
"type": "ComfyNumberConvert",
"pos": [
-295.0236493442684,
203.48293731896845
],
"size": [
178.0101231973421,
46
],
"flags": {},
"order": 12,
"mode": 0,
"inputs": [
{
"label": "value",
"name": "value",
"type": "INT,FLOAT,STRING,BOOLEAN",
"link": 89
}
],
"outputs": [
{
"name": "FLOAT",
"type": "FLOAT",
"links": null
},
{
"name": "INT",
"type": "INT",
"links": [
90
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyNumberConvert"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 6,
"type": "CLIPTextEncode",
"pos": [
558.700000000001,
160.40068341159756
],
"size": [
425.2650317382812,
167.9430462646484
],
"flags": {},
"order": 17,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 63
},
{
"name": "text",
"type": "STRING",
"widget": {
"name": "text"
},
"link": 96
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"slot_index": 0,
"links": [
70
]
}
],
"title": "CLIP Text Encode (Positive Prompt)",
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.39",
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
""
]
},
{
"id": 44,
"type": "CLIPLoader",
"pos": [
224.49879211425772,
292.66704483032197
],
"size": [
283.80000000000007,
106
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "CLIP",
"type": "CLIP",
"links": [
63,
64
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.73",
"Node name for S&R": "CLIPLoader"
},
"widgets_values": [
"qwen_3_8b.safetensors",
"flux2",
"default"
]
},
{
"id": 48,
"type": "UNETLoader",
"pos": [
917.2536154382312,
19.495025634765582
],
"size": [
308.1592787377913,
82
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "MODEL",
"type": "MODEL",
"links": [
69
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.9.2",
"Node name for S&R": "UNETLoader"
},
"widgets_values": [
"Flux.2/flux-2-klein-9b-fp8.safetensors",
"default"
]
},
{
"id": 56,
"type": "TextGenerate",
"pos": [
-722.3755914744937,
203.48293731896845
],
"size": [
400,
412
],
"flags": {},
"order": 10,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 87
},
{
"name": "image",
"shape": 7,
"type": "IMAGE",
"link": 102
},
{
"name": "video",
"shape": 7,
"type": "IMAGE",
"link": null
},
{
"name": "audio",
"shape": 7,
"type": "AUDIO",
"link": null
}
],
"outputs": [
{
"name": "generated_text",
"type": "STRING",
"links": [
89
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "TextGenerate"
},
"widgets_values": [
"この画像に女性が映っていれば 1 を、そうでなければ 0 を出力してください。",
256,
"on",
0.7,
64,
0.95,
0.05,
1.05,
0,
0,
false,
true
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 49,
"type": "ReferenceLatent",
"pos": [
1021.2781285510225,
160.40068341159756
],
"size": [
204.134765625,
46
],
"flags": {},
"order": 19,
"mode": 0,
"inputs": [
{
"name": "conditioning",
"type": "CONDITIONING",
"link": 70
},
{
"name": "latent",
"shape": 7,
"type": "LATENT",
"link": 75
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"links": [
71
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.9.2",
"Node name for S&R": "ReferenceLatent"
},
"widgets_values": []
},
{
"id": 59,
"type": "ComfyMathExpression",
"pos": [
-89.66158401670012,
203.48293731896845
],
"size": [
235.5094643140137,
143.8565237478972
],
"flags": {},
"order": 14,
"mode": 0,
"inputs": [
{
"label": "a",
"name": "values.a",
"type": "FLOAT,INT,BOOLEAN",
"link": 90
},
{
"label": "b",
"name": "values.b",
"shape": 7,
"type": "FLOAT,INT,BOOLEAN",
"link": null
}
],
"outputs": [
{
"name": "FLOAT",
"type": "FLOAT",
"links": null
},
{
"name": "INT",
"type": "INT",
"links": null
},
{
"name": "BOOL",
"type": "BOOLEAN",
"links": [
93
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyMathExpression"
},
"widgets_values": [
"a"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 64,
"type": "PrimitiveStringMultiline",
"pos": [
-252.1066255598296,
-220.87349522456816
],
"size": [
397.5504229008086,
144.88451526818943
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
95
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveStringMultiline"
},
"widgets_values": [
"Remove all people from the image."
],
"color": "#322",
"bgcolor": "#533"
},
{
"id": 65,
"type": "PrimitiveStringMultiline",
"pos": [
-248.07279349515574,
-20.209864694091635
],
"size": [
397.5504229008086,
144.88451526818943
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
94
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveStringMultiline"
},
"widgets_values": [
"Replace every woman in the image with a man, while keeping the same clothing, pose, position, hairstyle silhouette, lighting, camera angle, and scene composition."
],
"color": "#223",
"bgcolor": "#335"
},
{
"id": 63,
"type": "ComfySwitchNode",
"pos": [
220.08766704132302,
36.23429650683176
],
"size": [
270,
78
],
"flags": {},
"order": 16,
"mode": 0,
"inputs": [
{
"name": "on_false",
"type": "STRING",
"link": 95
},
{
"name": "on_true",
"type": "STRING",
"link": 94
},
{
"name": "switch",
"type": "BOOLEAN",
"widget": {
"name": "switch"
},
"link": 93
}
],
"outputs": [
{
"name": "output",
"type": "STRING",
"links": [
96,
98
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfySwitchNode"
},
"widgets_values": [
false
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 67,
"type": "PreviewAny",
"pos": [
561.1172245661597,
-48.8577314253514
],
"size": [
320.47592717353996,
140.40191931344805
],
"flags": {},
"order": 18,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 98
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
false
]
},
{
"id": 70,
"type": "CreateList",
"pos": [
-905.7143875874808,
484.74016932307575
],
"size": [
140,
66
],
"flags": {},
"order": 9,
"mode": 0,
"inputs": [
{
"label": "input0",
"name": "inputs.input0",
"type": "IMAGE",
"link": 100
},
{
"label": "input1",
"name": "inputs.input1",
"shape": 7,
"type": "IMAGE",
"link": 101
},
{
"label": "input2",
"name": "inputs.input2",
"shape": 7,
"type": "IMAGE",
"link": null
}
],
"outputs": [
{
"name": "list",
"shape": 6,
"type": "IMAGE",
"links": [
102,
103
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "CreateList"
}
},
{
"id": 51,
"type": "ResizeImageMaskNode",
"pos": [
209.97616959564456,
484.74016932307575
],
"size": [
270,
106
],
"flags": {},
"order": 11,
"mode": 0,
"inputs": [
{
"name": "input",
"type": "IMAGE,MASK",
"link": 103
}
],
"outputs": [
{
"name": "resized",
"type": "IMAGE",
"links": [
82
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.9.2",
"Node name for S&R": "ResizeImageMaskNode"
},
"widgets_values": [
"scale total pixels",
1,
"nearest-exact"
]
},
{
"id": 68,
"type": "LoadImage",
"pos": [
-1616.6685525637188,
486.1192079256388
],
"size": [
304.14064949086014,
536.4849883179598
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
100
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"000160_00004_.png",
"image"
]
},
{
"id": 62,
"type": "LoadImage",
"pos": [
-1266.6309825671176,
565.9597542315803
],
"size": [
304.14064949086014,
536.4849883179598
],
"flags": {},
"order": 7,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
101
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"000114_00005_.png",
"image"
]
},
{
"id": 31,
"type": "KSampler",
"pos": [
1262.7259909887628,
160.40068341159756
],
"size": [
315,
262
],
"flags": {},
"order": 20,
"mode": 0,
"inputs": [
{
"name": "model",
"type": "MODEL",
"link": 69
},
{
"name": "positive",
"type": "CONDITIONING",
"link": 71
},
{
"name": "negative",
"type": "CONDITIONING",
"link": 86
},
{
"name": "latent_image",
"type": "LATENT",
"link": 74
}
],
"outputs": [
{
"name": "LATENT",
"type": "LATENT",
"slot_index": 0,
"links": [
52
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.39",
"Node name for S&R": "KSampler"
},
"widgets_values": [
12345,
"fixed",
4,
1,
"euler",
"simple",
1
]
},
{
"id": 45,
"type": "SaveImage",
"pos": [
1813.4632685986182,
160.40068341159756
],
"size": [
684.1076792845461,
555.3306746679631
],
"flags": {},
"order": 22,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 65
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.73"
},
"widgets_values": [
"ComfyUI"
]
}
],
"links": [
[
52,
31,
0,
8,
0,
"LATENT"
],
[
62,
43,
0,
8,
1,
"VAE"
],
[
63,
44,
0,
6,
0,
"CLIP"
],
[
64,
44,
0,
33,
0,
"CLIP"
],
[
65,
8,
0,
45,
0,
"IMAGE"
],
[
69,
48,
0,
31,
0,
"MODEL"
],
[
70,
6,
0,
49,
0,
"CONDITIONING"
],
[
71,
49,
0,
31,
1,
"CONDITIONING"
],
[
74,
52,
0,
31,
3,
"LATENT"
],
[
75,
52,
0,
49,
1,
"LATENT"
],
[
76,
43,
0,
52,
1,
"VAE"
],
[
80,
54,
0,
52,
0,
"IMAGE"
],
[
82,
51,
0,
54,
0,
"IMAGE"
],
[
86,
33,
0,
31,
2,
"CONDITIONING"
],
[
87,
57,
0,
56,
0,
"CLIP"
],
[
89,
56,
0,
58,
0,
"STRING"
],
[
90,
58,
1,
59,
0,
"INT"
],
[
93,
59,
2,
63,
2,
"BOOLEAN"
],
[
94,
65,
0,
63,
1,
"STRING"
],
[
95,
64,
0,
63,
0,
"STRING"
],
[
96,
63,
0,
6,
1,
"STRING"
],
[
98,
63,
0,
67,
0,
"STRING"
],
[
100,
68,
0,
70,
0,
"IMAGE"
],
[
101,
62,
0,
70,
1,
"IMAGE"
],
[
102,
70,
0,
56,
1,
"IMAGE"
],
[
103,
70,
0,
51,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.4189769069935071,
"offset": [
1847.0845643468651,
533.2709120844096
]
},
"frontendVersion": "1.44.19",
"VHS_latentpreview": false,
"VHS_latentpreviewrate": 0,
"VHS_MetadataImage": true,
"VHS_KeepIntermediate": true
},
"version": 0.4
}
- 让 MLLM 查看图像,如果画面中有女性就输出
1,否则输出0 - 当结果为
true时,切换到“将女性改成男性”的提示词;为false时,切换到“删除人物”的提示词 - 将图像和提示词传给 Flux.2 Klein 9B 进行图像编辑