LayerUtility: RestoreCropBox
RestoreCropBox — paste a processed crop back where it came from
- background_image
- croped_image
- crop_box
- croped_mask
- image
- mask
This is the second half of the crop-fix-restore pattern. You cropped a region out of a larger image - a face, a hand, a product - ran it through some processing at higher detail, and now you need to put it back exactly where it was. RestoreCropBox does that. It takes the original background, your processed crop, and the crop box coordinates, and stitches the crop back into place seamlessly.
It's the partner to the pack's crop-by-mask node. The pattern is everywhere: crop the face, upscale or detail it, restore it to the full frame without re-rendering the whole image. This node is what makes that loop close cleanly instead of you eyeballing an offset in a paste node.
How it works
When you crop with the matching node, it emits a crop_box - the coordinates and size of what it took. RestoreCropBox reads that box and knows precisely where the crop belongs, so it drops your (possibly modified) crop back into the background at the right spot. If you supply a mask for the crop, it uses that to blend the paste rather than hard-pasting a rectangle, which is what keeps the seam invisible.
The inputs and outputs that matter
crop_box(BOX) - the coordinates from the crop node. This is the load-bearing input; it must be the box that produced this crop, or the paste lands in the wrong place or the wrong size.background_image- the full original image the crop came from.croped_image- your processed crop (the node keeps the original's spelling, "croped").croped_mask(optional) - blend the paste through this mask for a soft, seamless edge instead of a hard rectangle.invert_mask(default false) - flip the mask polarity if the blend is backwards.
Outputs: the reassembled image and a mask.
How to install it
Comes with the LayerStyle pack. ComfyUI Manager → search LayerStyle → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle
pip install -r ComfyUI_LayerStyle/requirements.txt
then restart. Under 😺dzNodes → LayerUtility. No model download.
Common issues & troubleshooting
The crop pastes in the wrong spot or scaled wrong. The crop_box has to be the exact one from the crop step that made this crop. Mixing boxes from different crops, or resizing the crop to a different pixel size than it was cut at, throws off the placement. Keep the crop→restore pair matched.
Visible seam or hard rectangle edge. Feed a croped_mask so the paste blends instead of butting a rectangle against the background. Feathering that mask a little hides the join.
Blend is inverted. Toggle invert_mask - the recurring LayerStyle mask-polarity thing.
Node isn't in the menu. The LayerStyle pack didn't import - the usual cause is a broken transformers dependency (a stray TensorFlow) crashing the whole pack on load. Check the traceback, use Manager's "Try Fix," or repair the named library.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| background_image | IMAGE | — | |
| croped_image | IMAGE | — | |
| invert_mask | BOOLEAN | false | — |
| crop_box | BOX | — | |
| croped_maskopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |