Nodes/Canvas/Canvas Transform
ComfyUI Node

Canvas Transform

Crop and grow

By leocbehe·Created about a year ago·Updated about a year ago· 0
Canvas Transform
  • input_canvas_image
  • transformed_canvas
operationcrop
grow_modeconstant
grow_fill_value0.00
margin_t0
margin_b0
margin_l0
margin_r0

Canvas Transform is the geometry node of the leocbehe/canvas pack: it grows a canvas before the model fills in the new area, or trims it back after. No sampling, no masking logic - just crop and pad, done the way the pack likes it.

What it does

Feed it any IMAGE (input_canvas_image) and pick an operation: crop slices pixels off the edges, grow pads them on. Either way the four margin_t / margin_b / margin_l / margin_r widgets decide how many pixels from the top, bottom, left, and right, each 0–4096 in steps of 8. The step matters: it keeps every dimension a multiple of 8, so whatever you hand downstream stays latent-friendly.

grow has four fill modes. constant (default) pads with a solid value - grow_fill_value, 0.0 to 1.0, where 0 is black and 1 is white. reflect, replicate, and circular mirror, repeat the edge pixels, or tile the image instead. replicate is the boringly useful one for outpaint prep: the model gets something to blend from rather than a hard color wall. Internally it's torch.nn.functional.pad with each mode, which is exactly as cheap as it sounds.

Where it fits

The KB's modern outpainting trick is to pad the canvas with a solid color and ask the instruction model to replace it - "remove the red padding and show what's behind it" is a real workflow people run. Canvas Transform is the padding half of that: grow the canvas by your target margin, then mask the empty region and generate. The crop half is just as useful after the fact: outpaint a region, then trim the ragged seam edges back off the final composite.

One honest caveat: this is a raw geometry node. It pads pixels; it does not know about masks or outpainting. You still have to mask the new area and run the sampler yourself, and if the untouched original must survive byte-for-byte while extending it, the community's dedicated crop-and-stitch tools handle that more cleanly than this pack's manual loop. Use Transform when you want the simplest possible "make the slab bigger / trim the slab" step.

Installing

Same pack, same story as the rest of the Canvas nodes. ComfyUI Manager → search "Canvas", or:

cd ComfyUI/custom_nodes
git clone https://github.com/leocbehe/canvas

Restart ComfyUI. No dependencies beyond what ComfyUI bundles, no model files, no keys. Like its siblings it's a brand-new personal project (version 0.0.1, GPL-3.0) - simple enough that it mostly just works, but young enough that you're testing it for the author.

CategoryCanvasNodes

Inputs (8)

NameTypeDefaultDescription
input_canvas_imageIMAGE
operationCOMBOcrop2 options: crop, grow
grow_modeCOMBOconstant4 options: constant, reflect, replicate, circular
grow_fill_valueFLOAT0.000–1Value to fill new pixels with if grow_mode is 'constant'
margin_tINT00–4096Number of pixels to crop/grow from the top of the canvas
margin_bINT00–4096Number of pixels to crop/grow from the bottom of the canvas
margin_lINT00–4096Number of pixels to crop/grow from the left of the canvas
margin_rINT00–4096Number of pixels to crop/grow from the right of the canvas

Outputs (1)

NameTypeDescription
transformed_canvasIMAGE