Advanced Parsing Overview
Inline Methods
Dynamic substitutions allow value calculation:
width: "{width:source}" # Width from the input "source".
height: "{height:source}" # Height from the input "source".
random_int: "{random:5,10}"
random_float: "{random:5.0,10.0}"
var: "{var:myvar}" # Value from previously assigned variable 'myvar'.
condition: "{exists:cache/mask.png}" # 1 if file exists. 0 if not.
Parsing
By default, any inline methods, like {var:…}
, {random:…}
, {exists:…}
, {width:…}
, and {height:…}
are automatically evaluated.
For simple evaluations (e.g. 20 + 5
), booleans, comparisons, and more, you can wrap your expression in double-brackets ([[ … ]]
).
Color Values
Color strings are processed using PIL.ImageColor.getcolor(color_str, "RGBA")
. Accepted formats include #RRGGBB
, rgba(...)
, and named colors.
Numeric Values
Supports inline math and methods:
w: "100"
x: "{var: x}" # Previously assigned variable.
y: "[[ 20/2 + (10 * 10) - 10 ]]"
z: "[[ {width:source}/2 ]]" # Inline math using input metadata.
Point Values
Coordinates can be specified as absolute or relative:
Absolute:
anchor: "(100,20)"
anchor2: "([[50*2]], {height:source})"
Relative:
relative_anchor: "rel(0.5,0.5)" # Relative to contextual value.
Behavior and Inheritance
-
Variable Inheritance:
Nested jobs inherit the parent's variables (including those set via assign blocks) for inline substitutions. -
Override Inheritance:
Nested jobs inherit a copy of the parent's structured overrides, merged into the nested job's definition during execution. -
Isolation:
Changes within a nested job (including overrides and variable assignments) do not affect the parent job.
Inline Methods (Always Parsed)
- What:
{var:…}
,{exists:…}
,{random:…}
,{width:…}
,{height:…}
,rel(…)
, etc. - When: Always applied first, on every value, before any math or condition logic.
- Nesting: If you write an inline method inside another (e.g.
{var:myvar{random:1,10}}
), the inner{random:…}
runs first, then its result feeds into the outer{var:…}
lookup.
Double-bracket parsing
- Trigger: Any value containing
[[…]]
. - Scope: Only the text inside each
[[…]]
is evaluated—everything else remains exactly as written. - Capabilities:
- Full boolean & comparison logic
- Ternary expressions (
a if cond else b
) - Tuple math (
(x+5, y*0.5)
) - Math functions (
abs()
,round()
,min()
,max()
,math.floor()
, etc.) - Inline methods can still be used inside
[[…]]
.
Escaping Brackets
- To include literal
[[
or]]
without triggering advanced evaluation, prefix them with a backslash:message: "\[\[ escaped double brackets \]\]"
-
You can mix escapes and eval:
text: "\[\[unparsed\]\] 2+2=[[ 2 + 2 ]]" # → "[[unparsed]] 2+2=4"
Examples
-
Arithmetic & Math
+ - * / % **
- e.g.
[[ ({var:width} + {var:padding}) * 2 ]]
-
Booleans & Comparisons
and
,or
,not
<, <=, >, >=, ==, !=
- e.g.
[[ not {var:done} ]]
- e.g.
[[ {var:count} > 3 and {var:flag} ]]
-
Ternary (Conditional) Expressions
a if cond else b
- e.g.
[[ {var:padding} if {var:width} > 1000 else 10 ]]
-
Math Functions
abs()
,round()
,min()
,max()
,math.floor()
,math.ceil()
,math.sqrt()
- e.g.
[[ round( max({var:width}, {var:height}) / 2 ) ]]
-
Inline Methods Inside Brackets
- You can mix any inline method inside your bracketed expressions:
{var:…}
for variables{exists:…}
for file existence{random:…}
,{width:…}
,{height:…}
, etc.
- You can mix any inline method inside your bracketed expressions:
Examples
# 1) Conditional step
- processor:
processor: "trim"
condition: "[[ {width:source} > 800 ]]"
# 2) Ternary padding
params:
padding: "[[ {var:padding} if {width:source} >= 1024 else 10 ]]"
# 3) Composite anchors with tuple math
- processor:
processor: "composite"
params:
overlay_anchor: " ( [[{width:background}/2]], [[{height:background}/2]] ) "
# 4) Boolean + exists + var
- processor:
processor: "inpaint"
condition: '[[ "{exists:cache/mask.png}" and not {var:skipped} ]]'
# 5) Using math functions
params:
blur_radius: "[[ round( {var:shadow_scale} * 2.5 ) ]]"
# 6) Comparison with multiple vars
- processor:
processor: "example"
condition: "[[ {var:count} > 3 and {var:enabled} ]]"