Image On Canvas
Drop an image on a colored canvas at any size and position
- image
- IMAGE
A deterministic compositing node: take an image, resize it to whatever dimensions you want, paste it at an x/y position onto a canvas of a fixed size filled with a solid hex background color. No alpha blending, no masks, no models. Resize and paste is the whole job, and it runs in milliseconds.
That determinism is exactly the point. This is the kind of thing you could do in Photoshop after the fact, but doing it inside the graph keeps the whole pipeline reproducible - and lets you feed the result straight back into the model. A favorite use is padding: generate at one aspect ratio, drop it onto a canvas sized for a ControlNet or an img2img that's picky about resolution, and let the background color fill the rest. It's also the workhorse for collages - character sheets, before/after grids, sprite and contact sheets - where you pack several generations into one frame for sharing or for a single pass through an upscaler. The KB's post-processing doc makes the case this layer is built on: don't burn a diffusion pass to do what a deterministic pixel op does instantly.
How it works
The mechanics are simple and honest. A PIL canvas is created at container_width × container_height and filled with your hex color (both #RGB and #RRGGBB shorthand work; a bad hex silently falls back to white with a console warning). Your image is resized with LANCZOS - the high-quality resample, not a neural upscaler - and pasted at the position you give it. If the pasted region would run past the canvas edge, it's clamped and cropped rather than erroring.
The inputs that matter
image- the IMAGE tensor you're placing.container_width/container_height- the canvas size, 1–8192, default 512×512.image_x/image_y- top-left corner position of the image on the canvas, default 0,0.image_width/image_height- the size to render the image at, default 256×256.background_color- hex string, default#FFFFFF.
Output: IMAGE.
Where people get burned
- Aspect ratio is not preserved. It stretches your image to exactly
image_width×image_height. Great for filling a slot, rough on subjects - a square image forced into a 256×64 bar comes out squashed. Compute your own w/h if you care about the ratio, because nothing here will do it for you. - Origin is top-left, and there's no centering helper. To center an image you do the arithmetic yourself:
x = (container_width − image_width) / 2. Easy, just don't forget it exists. - Only the first frame of a batch is used. If you feed it a 4-image batch, frames 2–4 are quietly dropped. Loop over them or split the batch first.
- Push it fully off-canvas and it silently vanishes. If
image_xis past the canvas edge, the paste is skipped and you get a blank canvas in your background color. No error, just an empty result. - LANCZOS is hardcoded. Fine for photos, but if you're placing pixel art you'll want nearest-neighbor replication instead - this node can't do it, so reach for a dedicated tool for sprites.
Installation
Same pack as the other two nodes in comfyui_andalusi - no requirements.txt, no model downloads, nothing beyond what ComfyUI already ships.
cd ComfyUI/custom_nodes
git clone https://github.com/AndalusiLLC/comfyui_andalusi.git
Restart ComfyUI, or install via ComfyUI Manager by searching for "Andalusi." It's a small personal pack - clean, readable source, but don't expect updates.
Troubleshooting
- Output is all one color - either the background hex was invalid (it defaults to white), or the image landed off-canvas. Check your x/y against the container size.
- Image looks stretched - your
image_width/image_heightdon't match the source's aspect ratio. That's the node doing exactly what you asked; fix the numbers. - Batch disappeared - remember it takes frame 0 only. Batch-split upstream if you need every frame.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| background_color | STRING | #FFFFFF | Background color in hex format (e.g., #FF0000 for red) |
| container_width | INT | 5121–8192 | Width of the canvas container |
| container_height | INT | 5121–8192 | Height of the canvas container |
| image_x | INT | 00–8192 | X position of the image on the canvas |
| image_y | INT | 00–8192 | Y position of the image on the canvas |
| image_width | INT | 2561–8192 | Width of the image on the canvas |
| image_height | INT | 2561–8192 | Height of the image on the canvas |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |