Mpi Crop
The anchor-aware crop that respects your model's divisibility
- image
- image
- width
- height
ComfyUI's built-in image handling will happily hand a model a 1347×771 image, and then the model complains because its latent space wants multiples of 8. That's the quiet annoyance MpiCrop exists for: it crops an image to a target size, anchored where you choose, and floors the result to a multiple of a divisible_by value - so you get a crop that's actually legal for your model. It's the boring utility that saves you from a stream of "size mismatch" errors.
How it works
Give it an image, a width and height, a divisible_by, and a position anchor. The crop region is placed per the anchor, and the final dimensions are floored to a multiple of divisible_by.
The detail that makes it flexible: width and height of 0 mean "keep that dimension full." So MpiCrop doubles as a pure divisibility trimmer - set width=height=0, divisible_by=8, and it just shaves the image down to legal multiples without cropping content away. Set width=1024, height=0 and it crops width to 1024 but keeps the full height, anchored by position.
The position enum is the five anchors that matter: center, left, right, top, bottom. Cropping to a portrait box? Use center so you don't lop off a head. Cropping a wide strip from the top of a frame? top. The anchor decides which region survives when the source is bigger than the target.
The inputs that matter
width/height- target crop size;0= keep full.divisible_by- the floor-to-multiple factor.8for the SD/SDXL family,16if you're feeding something pickier.position- which side of the image the crop hugs.
Outputs: the cropped image, plus the width and height that were actually produced - handy if a downstream node needs to know the real size after the divisible-by trim did its thing.
Where people get burned
The floor-to-multiple is a floor, not a round. Ask for 1030 wide with divisible_by=8 and you get 1024, not 1032. If you specifically need a size you can't get by flooring, size up first and crop down.
Also note the interaction between width and source: the crop never upscales. A width larger than the source is clamped to the source width. If you want to grow an image to a target, you want an upscale/resize node, not this. And unlike the pack's MpiBoxCrop, this one takes plain width/height/position widgets - no MPI_BOX wire - which makes it the right tool when the region is a simple centered or edge-anchored box rather than a free-form rectangle.
Install
From the MadPonyInteractive/ComfyUi-MpiNodes pack. ComfyUI Manager → search ComfyUi-MpiNodes (publisher mad-pony-interactive), install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes
then restart. No dependencies, no models to download - pure tensor math. The pack is AGPL-3.0 (≤ 1.2.6 MIT) and is the node library behind the author's Cubric Vision app.
The verdict
If every image in your pipeline is already a clean multiple of 8, you'll rarely touch it. But the moment you load arbitrary images - crops from a phone, stills from video, tiles from an upscale - and feed them to a model that sulks at odd dimensions, this is the node that keeps the graph running. Center-anchored crops, edge-trimming to legal sizes, and no surprises.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| width | INT | 00–4294967295 | Target crop width. 0 = keep full width (only divisible-by trim applies). |
| height | INT | 00–4294967295 | Target crop height. 0 = keep full height (only divisible-by trim applies). |
| divisible_by | INT | 11–256 | Final crop size is floored to a multiple of this. |
| position | COMBO | 5 options: center, left, right, top, bottom |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| width | INT | — |
| height | INT | — |