Reference Grid
Contact sheets with actual layout control — not just a crop-everything grid
- reference_images
- image
- mask
Contact-sheet reference grids are everywhere in local video work: you've got a character, a handful of reference photos showing them from different angles, and you want one composite image that hands all of them to the model at once. The stock way to do this is a quick grid node, and the stock result is square cells that center-crop everything - half your portrait gets lopped off, and the model never sees it.
Reference Grid is the version where you actually control the layout. It arranges references into a grid with per-cell fit behavior, cell sizing rules, fill order, and alignment for the ragged last row. If you've ever lost the edges of a wide reference to a dumb square cell, this is the node that stops that.
How it works
Every reference (from a MoonPack Image List or a stacked batch) gets normalized into its own cell. columns sets the column count - 0 auto-picks ceil(sqrt(n)), so 12 refs become a 4×3 grid, roughly square. Then the controls do their thing:
fit_mode-coverscales to fill and center-crops the overflow (the default, but now it's your choice);containscales to fit and pads the leftover with the fill color;stretchforces an exact fit and distorts the aspect ratio.cell_size_source-largest/smallest/averagepicks which references set the cell size, per axis independently. Feed one 4K and three 512px refs?largestupscales the small ones to match;smallestdoes the reverse.cell_width/cell_height- fixed overrides. Set both andcell_size_sourceis moot.fill_direction-row_major(left→right, then down) orcolumn_major(top→bottom, then across).last_row_align-left/center/rightfor the incomplete trailing row (or column, when column-major).fill,interpolation,max_ref_side,invert_mask- the shared knob set: background color, resampling filter, a downscale-only cap on oversized references, and mask flipping.
The mask output is the quietly important one
Outputs: the grid image and a mask. The mask marks exactly the real reference pixels - it excludes empty cells and any contain padding. That's not an afterthought: if you're feeding this composite to a video model that accepts a mask, you can hand it a mask that says "these pixels are the subject, those are padding." It's the difference between the model paying attention to your character and paying attention to dead space.
Reference Grid vs. Reference Concat's auto grid
This pack has two grid-ish paths and they're not interchangeable. Reference Concat with no main_image produces an auto-laid-out justified contact sheet with zero control - it's a convenience. Reference Grid is the full instrument. If you want a specific column count, a contain-fit with padding, or an aligned last row, this is the one.
Installing it
Reference Grid ships in MoonPack (comfyui-moonpack). Install via ComfyUI Manager (search MoonPack) or:
cd ComfyUI/custom_nodes
git clone https://github.com/moonwhaler/comfyui-moonpack.git
Restart ComfyUI. No models to download, no extra dependencies beyond what ComfyUI ships.
Where people trip up
The default cover fit crops - it's the right default for grids, but if your references have unusual aspect ratios you will lose content until you switch to contain. And in contain mode, remember the padding is only fill color; the mask is the only thing that knows where the actual image is. Check it once before you trust the composite.
Inputs (12)
| Name | Type | Default | Description |
|---|---|---|---|
| reference_images | IMAGE | Reference images to arrange into a grid. Connect a MoonPack Image List to keep each image's native resolution (recommended for mixed-resolution references), or a plain stacked IMAGE batch. | |
| columns | INT | 00–8192 | Number of grid columns. 0 = auto (ceil(sqrt(n)), a roughly square grid). |
| fit_mode | COMBO | cover | How each reference fills its cell. 'cover': scale to fill, center-crop the overflow. 'contain': scale to fit inside, pad the leftover with fill color. 'stretch': force an exact fit, distorting aspect ratio. |
| cell_size_source | COMBO | largest | Which references set the cell size (per axis, independently): the largest reference (upscales smaller ones), the smallest (downscales larger ones), or the average dimensions. |
| cell_width | INT | 00–8192 | Fixed cell width override. 0 = use cell_size_source. |
| cell_height | INT | 00–8192 | Fixed cell height override. 0 = use cell_size_source. |
| fill_direction | COMBO | row_major | Order references fill the grid. 'row_major': left to right, then top to bottom. 'column_major': top to bottom, then left to right. |
| last_row_align | COMBO | left | Alignment of the incomplete trailing row (row_major) or column (column_major, where left/right act as top/bottom) when the reference count doesn't evenly divide the grid. |
| fill | COMBO | black | Background color for empty cells and any 'contain' padding. 'edge_average' uses the mean color of all references. |
| interpolation | COMBO | bicubic | Resampling filter used whenever a reference image is resized. |
| max_ref_side | INT | 00–8192 | Caps each reference's longest side to this many pixels before any other processing (downscale only, never upscales). Keeps one oversized reference from blowing up the grid size. 0 = no cap. |
| invert_mask | BOOLEAN | false | Flip the output mask (empty/padding area becomes 1.0 instead of the reference area). |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |