AIHub Utils Crop Merged Image To Layer Size
The fallback crop that makes merged-image workflows work on stubborn clients
- merged_image
- merged_mask
- IMAGE
- MASK
AIHubUtilsCropMergedImageToLayerSize exists because not every editor plugin can do the convenient thing. In the otavanopisto ComfyUI-aihub-workflow-exposer pack, the AIHubExposeImage node can hand you a "merged image with the current layer's intersection" - pixel data pre-cropped to exactly what your workflow wants. But the README is upfront that some image programs can't provide those fancy types. When your client can only send a plain merged image plus the layer's coordinates, this node reconstructs the crop yourself: it takes the merged image and cuts it down to the layer's bounding box.
Think of it as the compatibility shim in the middle of the layer-image story. The expose node gives you a merged image, a pos_x/pos_y, and a layer size; this node turns those into the cropped IMAGE (and optional MASK) your inpainting or region-based nodes actually want.
The inputs that matter
- merged_image - the flattened, canvas-sized image from your expose node (typically
merged_imageormerged_image_without_current_layer). - layer_pos_x / layer_pos_y - where the layer sits in the canvas (from the expose's
pos_x/pos_youtputs). Range ±10000. - layer_width / layer_height - the layer's dimensions (default 512×512).
- merged_mask (optional) - the merged image's mask, cropped with the same coordinates so it stays aligned with the image. Skip it if you only need the pixels.
Outputs are IMAGE and MASK, both already cropped. Wire them straight into whatever processes your layer region - inpaint, outpaint, img2img within the selection.
How it actually behaves
The source does a simple clamp-and-crop: it intersects the layer's bounding box with the merged image's bounds, then slices. Two consequences worth knowing. First, a layer that sticks out past the canvas edge gets cropped at the canvas boundary - you get the visible portion, not an error. Second, a layer completely off-canvas produces a zero-size crop, so keep your coordinates sane. Because it's a plain tensor slice, there's no resampling, no quality loss, no surprises - what you crop is what the expose gave you.
When to reach for it (and when not to)
The README's own framing: this is the fallback node for clients that can't deliver merged_image_current_layer_intersection (or the variant without the current layer). If your client can hand you the pre-intersected image, use that and skip this node entirely - fewer moving parts. If it can't, this is your best friend: feed it the merged image + the layer's position and size, and downstream nodes never need to know the client was lazy.
Install and the usual caveat
Pack-standard, no requirements:
cd ComfyUI/custom_nodes
git clone https://github.com/otavanopisto/ComfyUI-aihub-workflow-exposer
Restart ComfyUI. The honest framing: this node is dead weight if you're not building an AIHub editor integration - it only makes sense in a workflow that receives merged layer images from a client. But in that context, it's the difference between "your workflow works with every client" and "your workflow only works with the clients that bothered to implement the fancy expose types."
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| merged_image | IMAGE | — | |
| layer_pos_x | INT | 0-10000–10000 | The X position of the layer in the canvas |
| layer_pos_y | INT | 0-10000–10000 | The Y position of the layer in the canvas |
| layer_width | INT | 5121–10000 | The width of the layer |
| layer_height | INT | 5121–10000 | The height of the layer |
| merged_maskopt | MASK | The mask of the merged image |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |