Image Prep For ICLora
Build the reference-plus-canvas image an in-context LoRA needs
- reference_image
- latent_image
- latent_mask
- reference_mask
- IMAGE
- MASK
In-context LoRAs (ICLoRAs) work by a slightly unusual trick: instead of just conditioning on a text prompt, the model is trained to look at a reference image placed alongside a generation canvas in a single combined image, and carry details - a subject, a style, a garment - across from one side to the other. That combined image has to be assembled a specific way for the technique to work: reference on one side, generation target on the other, sized and bordered consistently with how the LoRA was trained. ImagePrepForICLora is the node that assembles it, so you're not manually compositing canvases in an external editor before every run.
How it works
It places your reference_image and an optional latent_image (the canvas where new content will actually be generated) onto one combined output sized output_width × output_height, separated by border_width pixels of gap. Alongside the composited image, it produces a mask marking which region is the reference (protected, already-known content) versus which region is the generation target (what the sampler should actually fill in) - built from latent_mask and reference_mask if you supply them, or generated automatically from the layout otherwise.
The inputs and outputs that matter
reference_image- the image carrying whatever the LoRA should pull across: a subject, a style, an outfit, whatever it was trained to transfer.output_width/output_height(both default 1024) - the size of the final combined canvas. This needs to match whatever resolution the specific ICLoRA you're using expects, since these layouts are typically trained at a fixed size.border_width(default 0) - the gap between the reference side and the generation side. Some ICLoRAs are trained with a visible border between the two halves and expect one at inference time too.
Three optional inputs round out more advanced setups: latent_image (a starting canvas for the generation side, rather than leaving it blank), latent_mask, and reference_mask (for masking specific regions on either side rather than treating each half as all-or-nothing).
Two outputs: IMAGE, the assembled reference-plus-canvas composite ready to feed your sampler, and MASK, marking the generation region.
How to install it
Via ComfyUI Manager: search "KJNodes for ComfyUI," install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/kijai/ComfyUI-KJNodes
pip install -r ComfyUI-KJNodes/requirements.txt
then restart. This node only assembles the input image - it doesn't include or download any ICLoRA itself; you'll need that loaded separately in your graph.
Common issues & troubleshooting
Generated content doesn't resemble the reference at all. Check output_width/output_height actually match what your specific ICLoRA was trained at - a mismatched canvas size is one of the more common ways this class of technique silently underperforms, since the model learned a fixed spatial layout, not an arbitrary one.
The reference bleeds into the generated region, or vice versa. Increase border_width if your LoRA supports one, and check the mask output is actually reaching your sampler correctly rather than being ignored - the mask is what keeps the two halves separated during sampling, not just the visual gap in the composited image.
This is a genuinely under-documented technique. In-context LoRA image prep isn't something modidex has a dedicated writeup on yet, and the node's own description is blank beyond its schema - if a specific ICLoRA's expected layout isn't obvious from its own model card or example workflow, that's the actual source of truth to check, not general defaults.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| reference_image | IMAGE | — | |
| output_width | INT | 10241–4096 | — |
| output_height | INT | 10241–4096 | — |
| border_width | INT | 00–4096 | — |
| latent_imageopt | IMAGE | — | |
| latent_maskopt | MASK | — | |
| reference_maskopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |