fix: use source_image dimensions as fallback when template uses node-refs for size

Templates like wan_video_i2v wire WanImageToVideo width/height to the output
of an ImageResizeKJv2 node — these are runtime values, not stored in the JSON.
extract_resolution reads the resize node's *input* params (512x512) which is
the resize target, not the actual output size.

Fix: extract_resolution now sets _width_from_node_ref / _height_from_node_ref
flags when width/height are node references. execute() checks these flags and,
when the user hasn't set an explicit UI override, reads actual dimensions from
the source_image tensor shape ([B, H, W, C]) instead. This correctly handles
i2v (and any future template) where the output size tracks the input image.
This commit is contained in:
FranckyB
2026-04-11 21:37:54 +00:00
parent 3df92b0509
commit 0fa7eec08d
2 changed files with 20 additions and 0 deletions
+16
View File
@@ -1058,6 +1058,22 @@ class WorkflowGenerator:
return int(default)
width = _to_int(overrides.get('width', res['width']), 512)
height = _to_int(overrides.get('height', res['height']), 512)
# Last-resort fallback: if the template wires width/height to a
# runtime node-ref (e.g. ImageResizeKJv2 output in i2v), the static
# JSON value is just the resize target, not the actual output size.
# In that case — and when no UI override was set — read the real
# dimensions directly from the source_image tensor instead.
if source_image is not None and hasattr(source_image, 'shape'):
src_h = source_image.shape[1] # [B, H, W, C]
src_w = source_image.shape[2]
w_is_ref = res.get('_width_from_node_ref', False)
h_is_ref = res.get('_height_from_node_ref', False)
# Only override when the template used a node-ref (runtime value)
# AND the user hasn't explicitly set width/height via the UI.
if w_is_ref and 'width' not in overrides:
width = src_w
if h_is_ref and 'height' not in overrides:
height = src_h
length = overrides.get('length', res.get('length'))
batch = (
_to_int(length, 1) if length is not None
+4
View File
@@ -359,6 +359,10 @@ def extract_resolution(prompt_data, workflow_data):
w = inp.get('width', resolution['width'])
h = inp.get('height', resolution['height'])
b = inp.get('batch_size', resolution['batch_size'])
# Track whether width/height came from node-refs (runtime values)
# so execute() knows it can use source_image dims as a better fallback.
resolution['_width_from_node_ref'] = isinstance(w, list)
resolution['_height_from_node_ref'] = isinstance(h, list)
resolution['width'] = _scalar(w, resolution['width'], 'width')
resolution['height'] = _scalar(h, resolution['height'], 'height')
# batch_size in WanImageToVideo can equal 'length' — clamp to 1 if > 64