Mpi Box Crop
Crop to a rectangle that's allowed to hang off the edge
- image
- mpi_box
- image
- mpi_box
Mpi Box Crop is what you get when you want to crop an image to a region without playing defense against the edges. It takes an image and an MPI_BOX, crops to the box, and - the part that makes it worth a node - handles every way the box can hang off the image without blowing up. You build the box with Mpi Box (where x/y are the top-left corner and may be negative), and this crops to it.
The mechanism is where the care went in. The box is clamped to the image first, so anything sticking out past the borders is silently trimmed to what actually exists. A box fully outside the image passes the image through unchanged - you get your source image back, not a crash or a nonsense crop. And crucially, the node outputs the clamped box right alongside the crop (mpi_box output), so whatever comes next sees the region that was actually used, not the region you asked for. That's the detail that saves you from a whole class of off-by-the-edge bugs: downstream nodes know the truth about where the crop ended up.
Inputs: image (IMAGE) and mpi_box (MPI_BOX, forceInput). Outputs: image (the crop) and mpi_box (the clamped box actually used). There's one optional input that matters and it's the reason this node exists for a specific job: pad, a BOOLEAN defaulting to off. Its tooltip is the whole story - "Pad the crop back out to the requested box size when the box overhangs the image, replicating the edge pixels. Off, the crop is just the intersection."
Why does pad exist? Turn it on and an overhanging box is padded back out to its requested size by replicating the edge pixels, so the crop keeps the aspect ratio you asked for. That's precisely what a square reference crop needs - think a reference image for a video model or a control input that wants a fixed square - where you need the exact dimensions even if the region runs off the frame. The trade-off is visible: replicated edge pixels are fake data, fine for a reference or conditioning input, wrong for anything where those pixels get sampled as real content. The default (off) is the honest crop: just the intersection, no invented pixels.
Where people actually use this: localized detail passes (crop a face region for a separate render pass), reference-image prep for video, and the whole crop-edit-stitch loop that the KB's masking and inpainting docs describe - crop tight, re-render, composite back. The box-aware design means the region can be shared between this and Mpi Box Mask (mask the same box, inpaint the same region) with one MPI_BOX wire, which is the cleaner version of the loose-int crop-and-mask dance most packs make you do.
The honest caveat: it only speaks MPI_BOX. If you've got four loose ints and no Mpi Box in the graph, add one - it's the input this node expects, and Mpi From Box will unpack it again if you need loose ints on the other side.
Install is pack-standard: ComfyUI Manager → search ComfyUi-MpiNodes → install, or clone it:
cd ComfyUI/custom_nodes
git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes
Restart, and it's under MpiNodes/ImgOps. No requirements file, no model downloads.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mpi_box | MPI_BOX | — | |
| padopt | BOOLEAN | false | Pad the crop back out to the requested box size when the box overhangs the image, replicating the edge pixels. Off, the crop is just the intersection. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mpi_box | MPI_BOX | — |