Create Context Window
Build the window your in-context LoRA actually sees
- input_image
- input_mask
- prepared_image
- prepared_mask
- patch_mode
- x_offset_of_ori
- y_offset_of_ori
- scale
- crop_area
- crop_mask
If you've downloaded an in-context LoRA and stared at its example workflow wondering what builds that weird two-panel image, this is the node doing it. CreateContextWindow is the heart of lrzjason's pack: it takes your subject image plus a mask and lays the subject out into a clean, fixed-size "patch" panel that the LoRA can actually read. The generation quality is decided in that geometry long before the sampler runs, so this little node punches above its weight.
Here's the mental model. An in-context LoRA is trained on FLUX.1 Fill to take a composed context window - a reference subject on one side, an empty patch on the other - and fill the patch with the subject. It only sees that composed image, which means a sloppy, arbitrarily-sized crop will produce sloppier fills than a consistent panel. CreateContextWindow standardizes the panel: same aspect, same output length, subject centered with a bit of breathing room, every run.
How it works
The mechanism is straightforward OpenCV geometry, no model involved. The node runs your mask through contour detection to find the bounding box of what you actually masked, expands it by pixel_buffer, crops a region centered on the subject, and then resizes or letterboxes that crop into the target window - patch_type aspect at output_length. Out the other side you get the prepared panel, a prepared mask showing where the subject sits inside it, and the bookkeeping: the real patch_mode used, the x/y offsets of the subject in the original image, and the scale.
The inputs that matter
- patch_mode -
auto(default) picks the layout from your image: portrait →patch_right(reference left, patch right), landscape →patch_bottom(reference top, patch below). Set it manually only if you know the LoRA was trained one way. - patch_type -
3:4(default),1:1,9:16. This is the panel's aspect ratio, and most IC LoRAs are trained on one or two of these. Mismatch it and the fill degrades. Match the LoRA's model card. - output_length - the long edge in pixels, default 1536. Gets silently snapped down to a multiple of 64.
- pixel_buffer - default 64. Breathing room around the subject so the crop doesn't hug it; raise it if the subject touches the panel edge.
input_image and input_mask are both required. Feed no mask (or an all-zero one) and the node quietly treats the whole image as the subject, which is almost never what you want - mask your subject.
Outputs
prepared_image and prepared_mask are the ones you wire forward, into the Fill/Redux conditioning of the wider workflow. x_offset_of_ori, y_offset_of_ori and scale map the crop back onto the original image, which is what you need when a downstream node has to stitch the generated patch back in place. crop_area and crop_mask are the original-scale crop around the subject, handy for compositing.
Installing it
Same pack as everything else here - one install gets you all four nodes:
cd ComfyUI/custom_nodes && git clone https://github.com/lrzjason/Comfyui-In-Context-Lora-Utils
then restart ComfyUI. Or use Manager: search "Comfyui-In-Context-Lora-Utils". There's no requirements.txt and the pyproject declares no pip dependencies - the nodes are pure numpy/OpenCV. What you do need is the model stack the workflow expects: FLUX.1 Fill dev (unet), the T5 and CLIP-GmP text encoders, the Flux VAE, and for the reference conditioning Redux plus SigLIP - the README links all six. And you need the in-context LoRA itself; the pack doesn't ship one (the author's try-on LoRA lives on Civitai).
Gotchas
- Console spam.
DEBUG = Truein the source means every run prints a wall of===debug===lines to your terminal. Harmless, but it startled me the first time. - First frame only. Only
input_image[0]andinput_mask[0]are processed - batch inputs silently drop everything after the first frame. - It needs OpenCV. The pack imports
cv2at module load, and a fresh ComfyUI env can throwModuleNotFoundError: cv2. Most installs already have it via another pack; if not,pip install opencv-pythonin your ComfyUI environment fixes it. - The geometry had a rough launch. The changelog for Nov–Dec 2024 reads like a patch log ("fix cropping", "fix padding", "fix center point") - if you're on an old clone, update; the current math is far more stable.
The honest caveat for 2026: instruction-edit models (Klein, Qwen-Image-Edit) now handle try-on and outpainting from a prompt, so the IC LoRA genre is a 2024-era niche. But if your workflow is built on one, nothing else does this job - it's the difference between a LoRA that cooperates and one that fights your input every run.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| input_image | IMAGE | — | |
| input_mask | MASK | — | |
| patch_mode | COMBO | auto | 3 options: auto, patch_right, patch_bottom |
| patch_type | COMBO | 3:4 | 3 options: 3:4, 1:1, 9:16 |
| output_lengthopt | INT | 1536 | — |
| pixel_bufferopt | INT | 64 | — |
Outputs (8)
| Name | Type | Description |
|---|---|---|
| prepared_image | IMAGE | — |
| prepared_mask | MASK | — |
| patch_mode | STRING | — |
| x_offset_of_ori | INT | — |
| y_offset_of_ori | INT | — |
| scale | FLOAT | — |
| crop_area | IMAGE | — |
| crop_mask | MASK | — |