Auto Patch
Let the mask pick the patch layout for you
- image2
- mask2
- patch_mode
- patch_type
AutoPatch is the smallest node in lrzjason's in-context LoRA pack, and I'll say it plainly up front: it's optional. Its entire job is to look at the image you're about to patch and hand back two strings - patch_mode and patch_type - that you can plug straight into CreateContextWindow or ConcatContextWindow. It's a small automation so you don't have to guess the layout yourself.
If you're new to the genre, quick recap: in-context LoRAs are trained on FLUX.1 Fill to take a composed image - reference subject on one side, empty patch on the other - and fill the patch. The layout decisions are which side the patch goes on (right for portrait subjects, bottom for wide ones) and what aspect ratio the patch panel uses (1:1, 3:4, or 9:16). AutoPatch just makes those two decisions for you.
How it works
It runs the mask through the same OpenCV contour logic the bigger nodes use, finds the bounding box, and decides:
- patch_mode - the box is taller than wide →
patch_right; wider than tall →patch_bottom. - patch_type - whichever of 1:1, 3:4, or 9:16 is closest to the box's aspect ratio.
Pass mask2 and it measures your actual subject. Leave it empty and it treats the whole image as the subject (a full mask), which is the sane default for generate mode where you don't have a mask yet.
Inputs and outputs
That's the whole interface: image2 (required), mask2 (optional), and two STRING outputs, patch_mode and patch_type. Wire both into the matching ports on CreateContextWindow or ConcatContextWindow - you can even just feed them into a text box if you want to see what it picked.
Honest assessment of when it earns its keep: the other nodes already have auto as their default patch_mode, so in a one-off workflow this buys you almost nothing. Where it shines is batch work where subjects vary wildly between runs - a tall product one frame, a wide one the next - and you want each window laid out to match its own subject instead of one fixed setting.
One quirk worth knowing
If mask2 arrives at exactly 64×64, the code treats it as "no mask" and substitutes a full mask. It's a harmless edge case baked into the source, but it explains confusing behavior if your mask preprocessing ever downsizes to a square thumbnail before this node sees it.
Installing it
It ships in the same pack as everything else - one install, four nodes:
cd ComfyUI/custom_nodes && git clone https://github.com/lrzjason/Comfyui-In-Context-Lora-Utils
then restart ComfyUI. Or use ComfyUI Manager and search "Comfyui-In-Context-Lora-Utils". No pip dependencies (pure numpy/OpenCV), though your ComfyUI env needs opencv-python present - most installs already have it. Same console-debug noise as the rest of the pack, same "first frame only" batching.
Use it when you're automating; ignore it when you're not. That's the whole review.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image2 | IMAGE | — | |
| mask2opt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| patch_mode | STRING | — |
| patch_type | STRING | — |