ComfyUI Node

NB2 Crop

NB2 Crop — the crop half of the Nano Banana workaround

By amortegui84·Created 5 months ago·Updated 3 months ago· 3
NB2 Crop
  • image
  • mask
  • stitcher
  • cropped_image
  • cropped_mask
aspect_ratio16:9
resolution2K
context_extend_factor1.00
downscale_algorithmbilinear
upscale_algorithmbicubic
device_modegpu (much faster)

Nano Banana 2 can't inpaint, and people keep asking anyway. It's a generation model - no mask input, fixed output resolutions, and every edit rewrites the whole frame. The standard workaround, and the whole point of this pack, is crop-and-stitch: cut out the region you care about, regenerate only that, paste it back so every other pixel stays bit-identical.

NB2 Crop is the crop half. You give it the source image and a rectangular mask, and it cuts around the mask and resizes to exactly one of Nano Banana's fixed resolutions. The output you actually use is cropped_image (that goes into the NB2 edit node), and the stitcher output is a little bundle of coordinates that the stitch node will need later. Don't lose it - NB2 Stitch is useless without it.

This node is a stripped-down fork of lquesada's original InpaintCropAndStitch, simplified specifically for the NB2 case: no outpainting extension knobs, no debug outputs, just "crop to the mask and hit the exact resolution."

The two settings that must match

The tooltips on these are the author yelling at you through the schema:

  • aspect_ratio - "Must match the aspect_ratio set in NB2 Mask Generator." (16:9, 9:16, 1:1)
  • resolution - "Must match the resolution set in NB2 Mask Generator." (1K, 2K, 4K)

If the mask says 16:9 @ 2K and the crop says 9:16 @ 1K, you get a resampled, squished region and a seam the stitch can't hide. Match them and the crop lands on the exact NB2 output size: 2752×1536 for 16:9 @ 2K, and so on down the table the README prints.

The other inputs are set-and-forget. context_extend_factor (1.0–4.0, default 1.0) grows the crop region before the aspect-ratio fit - bump it past 1.0 if Nano Banana keeps inventing context-free surroundings and you want the model to see more of the original around the edit. downscale_algorithm / upscale_algorithm default to bilinear/bicubic, and device_mode defaults to gpu (much faster) - switch to cpu (compatible) only if you're on a machine that chokes on the GPU path.

Outputs: stitcher (into NB2 Stitch), cropped_image (into the edit node's image_1), and cropped_mask (handy for previewing, rarely used downstream).

Where it sits

NB2 Mask Generator (manual rectangle)   or   NB2 Smart Region (auto from a mask)
    -> NB2 Crop -> Nano Banana 2 Edit -> NB2 Stitch

If you're coming from a Florence-2 or SAM mask instead of a manual rectangle, put NB2 Smart Region between the selector and this node - it converts a semantic mask into the exact NB2-shaped rectangle this node expects.

Install & troubleshooting

Search comfyui-inpaint-cropstitch-nb2 in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/amortegui84/comfyui-inpaint-cropstitch-nb2

Restart, done - deps install on first launch, and there are no models to download. This node runs entirely locally (numpy/scipy/pillow); only the edit step needs the FAL key.

The most common failure isn't a crash - it's a wrong-sized crop because the mask node and crop node disagree on aspect/resolution. The second is a visible seam afterward, which is a stitch problem, not a crop one: head to NB2 Stitch and give edge_feather_percent a nudge above the default 5 if the border shows. And if the whole chain fails before the edit node, you're missing the FAL key - set FAL_KEY and restart ComfyUI completely, not just a browser refresh.

Categoryinpaint/nb2

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
aspect_ratioCOMBO16:9Must match the aspect_ratio set in NB2 Mask Generator.
resolutionCOMBO2KMust match the resolution set in NB2 Mask Generator.
context_extend_factorFLOAT1.001–4Grow the crop region by this factor in every direction before aspect-ratio adjustment. 1.0 = crop exactly the masked area.
downscale_algorithmCOMBObilinear6 options: nearest, bilinear, bicubic, lanczos, box, hamming
upscale_algorithmCOMBObicubic6 options: nearest, bilinear, bicubic, lanczos, box, hamming
device_modeCOMBOgpu (much faster)2 options: gpu (much faster), cpu (compatible)
maskoptMASK

Outputs (3)

NameTypeDescription
stitcherSTITCHER
cropped_imageIMAGE
cropped_maskMASK