Nodes/kubakub nodes/kubakub canvas to work
ComfyUI Node

kubakub canvas to work

Get your matrix onto the model's grid without breaking it

By kubakubkub·Created about a month ago·Updated 2 days ago· 10
kubakub canvas to work
  • image
  • canvas_plan
  • mask
  • image
  • mask
  • scope
◄aspect_modeerror►
◄pad_modereplicate►
◄resize_methodauto►

What it's for

This is the first half of a two-node sandwich. kubakub canvas plan decides the work size; kubakub canvas to work actually puts your image on it; kubakub canvas restore brings the result back.

You reach for it whenever you're running a whole-picture pass on a facade matrix - a Klein or Qwen edit, a style pass, a versions draft sheet - and you want the matrix itself to survive it. Resize-plus-stretch is what people do by default and it's what makes the ouput subtly wrong: same total pixels, wrong proportions. This node does a uniform resize (target ÷ k, one factor) and then pads up to the model's grid. No stretch, ever.

How it works

Two steps, in order. Uniform resize of the image to target / k from the plan, then pad on the smaller axis up to the model's grid. The padding goes where pad_align on the plan says - centred by default.

Then the part that makes it more than a resize: scope. The node emits a mask that is 1 on the real canvas and 0 on the grid padding. That single output is how you tell the rest of your graph "these pixels are the picture, those pixels are the model's training wheels". Wire it into a mask combine or a sampler's mask input and the padding stops mattering. Without it, downstream nodes happily treat replicated edge pixels as content, and diffusion is very willing to hallucinate a border into existence.

Optional masks ride along: give it a mask and it's resized and padded exactly like the image, so the mask stays in register. That's the difference between "approximate" and "works".

Inputs and outputs

  • image - matrix, start image, reference or first frame. Anything of the target's aspect.
  • canvas_plan - straight from canvas plan. Same plan object as restore uses; they have to match.
  • aspect_mode - what to do when the image's aspect differs from the target. error is the default and it means it: center_crop or pad are your explicit choices. It will not stretch for you, which is the whole philosophy of the node.
  • pad_mode - what the model sees in the padding: replicate, reflect, gray or black. Replicate is the safe default; reflect is nicer for images with a strong gradient toward the edges; flat grey/black ask the model to invent a border, which can be exactly what you want for a full bleed and usually isn't.
  • resize_method - auto means area when shrinking, lanczos when growing. Leave it.
  • mask (optional) - the mask that comes along for the ride.

Outputs: image (on the work canvas, padded), mask (same treatment), and scope.

Install

Manager → search kubakub nodes, install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/kubakubkub/ComfyUI_KubaNodes
python -m pip install -r ComfyUI_KubaNodes/requirements.txt

ComfyUI 0.37.0 or newer, OpenCV as the only added package, no models needed.

Common issues

  • "error" on a perfectly good image. Default aspect_mode is error and it compares against the plan's target aspect. If your matrix is 16:9 and you're feeding a 3:2 reference, that's expected - pick pad or center_crop on purpose rather than discovering later what happened.
  • Am I supposed to feed the target or the work size? The target. The node does the resize; handing it the already-scaled canvas just scales it twice.
  • Downstream node refuses the mask size. The mask comes out at the work canvas size (with padding), not your matrix size. That's correct, and it's why canvas restore restores the mask as well as the image.
  • Gradients at the edge look odd. Try reflect. Replicate produces a hard smeared line along the padded side, and if a big blur or a seam pass sits downstream, you'll see it.
Categorykubakub/2d/regions/canvas

Inputs (6)

NameTypeDefaultDescription
imageIMAGEThe image to bring onto the work canvas (matrix, start image, reference or first frame).
canvas_planKUBA_CANVAS_PLANFrom kubakub canvas plan.
aspect_modeCOMBOerrorIf the image's aspect differs from the target: error, center_crop, or pad (for references and first frames). Never stretch.
pad_modeCOMBOreplicateWhat the model sees in the grid padding.
resize_methodCOMBOautoResize filter: auto = area when shrinking, lanczos when growing.
maskoptMASKOptional mask, resized and padded the same way as the image.

Outputs (3)

NameTypeDescription
imageIMAGEThe image on the work canvas, padded to the model grid.
maskMASKThe input mask on the work canvas (zeros if none).
scopeMASK1 = target canvas, 0 = padding.