ExpandImageWithColor-badger
Pad your image with a border or a transparent frame — no resize node gymnastics
- image
- IMAGE
Sometimes you don't want to scale an image - you want to grow the canvas around it. A poster frame, a matte border, a transparent buffer before compositing, a padding band so a later crop doesn't bite off your subject. ExpandImageWithColor-badger does exactly one thing: takes your image, adds top/bottom/left/right pixels of space around it, and fills that space with either a solid color or pure transparency. It's the "letterbox without the upscale" node.
The resize-node habit dies hard, but padding is genuinely different. If you need a 1024×1024 canvas for a training batch or a video standard and your image is 896×1024, the pixel-perfect answer is pad the sides, don't stretch - stretching changes the content, padding doesn't. Combine this with ImageNormalization-badger (same pack, which computes exactly how much padding to add to hit a target aspect) and you've got a proper fit-to-canvas pipeline.
How it works
Pillow's Image.new does the heavy lifting. The node builds a new RGBA canvas sized to the original plus your padding, then pastes the original at the (left, top) offset. The fill depends on one optional input:
- color (optional, STRING, default empty) - a hex value like
"#ffffff". If you give it one, the border is that solid color and the result is converted back to RGB. If you leave it empty, the border is fully transparent and you get an RGBA image out.
Inputs and outputs
Required inputs:
- image - what you're padding.
- top / bottom / left / right - INTs, pixels of padding on each side. Defaults are all
0, so with no values changed the node is a no-op. These are the only settings that matter; remember the canvas grows byleft + righton the width andtop + bottomon the height.
One output: an IMAGE, now bigger, with either a colored frame or transparent margins. Feed the transparent variant into a compositing node for clean spacing, or save it as PNG.
Installing it
From the ComfyUI_BadgerTools pack. ComfyUI Manager → search "BadgerTools" → install → restart. Manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/AbyssYuan0/ComfyUI_BadgerTools
No model files involved. The pack-level caveat applies here too: the requirements list is heavy and imports at startup, so expect a slow first boot after install even though this node needs only Pillow and numpy.
Gotchas
- The
colorformat is strict. It expects#RRGGBB. No#and you'll hit a parse error, and it doesn't understand named colors like "red" - only hex. - Default is transparent, not white. If you don't pass a color you get a transparent border, which you may not expect if you were picturing a white matte. Pass
#fffffffor that. - Max padding is 1024 per side per the schema, which is plenty for letterboxing but not for "make this a billboard."
- One image at a time - the code reads the first image in the tensor.
There's no community lore to check for this one; it's a small personal-pack utility that does one job cleanly. If you've ever needed a padded canvas, you know how annoying it is to fake with resize nodes - this is the honest version.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| top | INT | 00–1024 | — |
| bottom | INT | 00–1024 | — |
| left | INT | 00–1024 | — |
| right | INT | 00–1024 | — |
| coloropt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |