Y7 Pad Image for Outpainting
Pad for outpainting without breaking the 8-pixel rule
- image
- image (original)
- image (padded)
- mask
- width
- height
If you've ever outpainted in ComfyUI and hit a "multiple of 8" error - or worse, got a subtly smeared canvas that you couldn't explain - this node is the fix. It's a clone of the built-in Pad Image for Outpainting, with exactly one thing added: a step input that snaps your padding values to the nearest multiple of 8 (or 16, or 64) before the pad happens. That's the whole trick, and it's a good one.
Why the snapping matters
Your image goes through a VAE, and VAEs downscale by 8x per side on the way into latent space (16 per side on newer models like Flux, which wants dimensions divisible by 64). If your padded canvas isn't a clean multiple, the latent gets rounded up and your "pad to 512" becomes "pad to 518" - and the outpaint result comes back offset, or with artifacts along the edge you were trying to extend. Manually doing (width + left + right) % 8 in your head before every outpainting run is exactly the kind of busywork nobody should do.
The built-in node assumes you'll type clean numbers. This one forgives you.
How it works
The source is short and honest: it fills a new, larger canvas with 0.5 grey (torch.ones * 0.5), drops your original image into the middle, and returns that plus a mask that's white in the padded region and feathered near the border. Each of left, top, right, and bottom (all INT, default 0) is snapped to the nearest multiple of step - ties round up - independently, so you can pad 64px top but 200px bottom and both land on the grid. feathering (default 40) is the width of the soft gradient where old and new meet; more feathering means the model blends the extension instead of seeing a hard seam.
Outputs are IMAGE and MASK. Wire the image and mask into a VAEEncodeForInpaint (or a fill model), set denoising around 0.8–1.0 for the extension area, and prompt for what should live in the new space. The mask is what protects your original pixels - outpainting is the one case where the mask really earns its keep when the original has to survive.
The gotchas
- Your typed value is not what gets applied. Snap the pad values and the node quietly changes them. Need a literal 256px? Set
stepto 1. That's the escape hatch, and it's the first thing to check if your output dimensions look slightly off. - Feathering silently turns off if
feathering * 2isn't smaller than the image's own width and height - the math skips it rather than failing, so a tiny image can end up with a hard mask edge and a visible pasted-on look. Drop the feathering value, or pad more. - This node only snaps; it won't make your composition obey the grid. Plan the pad, snap, then look at the actual output size before you sample.
Install
ComfyUI Manager → Custom Nodes Manager → search "Y7Nodes", install, restart. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/yushan777/ComfyUI-Y7Nodes
pip install -r requirements.txt
Note the pack's requirements.txt pulls in heavy stuff (transformers, sentencepiece, lmstudio) for its other nodes - this one only needs torch, which you already have. The author describes the whole pack as "probably only useful to me," but this is the rare quality-of-life clone that quietly saves every outpainting run a moment of arithmetic.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| step | INT | 161–1024 | Padding is rounded to a multiple of this number, so the final image stays a size the model is happy with. Also sets how far the +/- arrows move each side. |
| fill | COMBO | grey | What to put in the new area before outpainting. grey: flat 50% grey, same as the built-in node. edge replicate: smears the outermost pixels outwards. mirror: reflects the image back on itself. blurred edge: a soft blur of the nearby colours. noise: random noise in the image's own colours. It all gets painted over anyway, but a plausible starting colour usually gives a better outpaint than flat grey. |
| feathering | INT | 400–16384 | Width in pixels of the soft fade at the join between the original image and the new area. 0 gives a hard edge. |
| left | INT | 00–16384 | Pixels to add to the left edge. |
| top | INT | 00–16384 | Pixels to add to the top edge. |
| right | INT | 00–16384 | Pixels to add to the right edge. |
| bottom | INT | 00–16384 | Pixels to add to the bottom edge. |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| image (original) | IMAGE | The image exactly as it came in, unpadded. |
| image (padded) | IMAGE | The image on the enlarged canvas, with the new area filled. |
| mask | MASK | White over the new area, black over the original image, with the feathered ramp in between. |
| width | INT | Width of the padded image. |
| height | INT | Height of the padded image. |