Nodes/ComfyUI-PepeUtils/Load Image Cropped
ComfyUI Node

Load Image Cropped

Draw a crop box on the image instead of doing the math

By Pepehoschi·Created 5 months ago·Updated 12 days ago· 0
Load Image Cropped
    • image
    • mask
    • width
    • height
    image
    x10
    y10
    x20
    y20

    ComfyUI's plain LoadImage gives you the whole image, always. The moment you only want part of it - a face to feed a detailer, a subject to run through img2img, a region to use as a reference - you're stuck doing the crop in an external editor or guessing at numbers. Load Image Cropped is the fix: it's LoadImage with an interactive crop rectangle you drag directly on the preview in the frontend.

    That sounds like a small upgrade and it is, but it's the one that makes region workflows tolerable. You drop an image in, drag the green box around the part you care about, and the node hands back the cropped image plus the crop's dimensions as plain integers you can wire anywhere.

    How it works

    It's built on top of the same LoadImage machinery, with a twist: the crop rectangle lives in four INT widgets - x1, y1, x2, y2 - which the frontend hides and drives from the preview overlay. Drag the box on the canvas and those coordinates update in the background; the backend then crops image[:, y1:y2, x1:x2, :] and returns the result.

    The details are worth knowing:

    • Coordinates get clamped to the image bounds, and if the box is empty or inverted the node falls back to the full image. So a fresh node with 0,0,0,0 just loads the whole picture - no crash, no surprise.
    • It loads every frame of animated formats and crops each one, so an animated PNG or GIF input gives you a cropped batch rather than an error.
    • The frontend lets you drag a file straight onto the node to pick it, and a Clear Crop entry in the right-click menu resets the rectangle.

    Inputs and outputs

    The one input you actually touch is image - the file dropdown, which you can also fill by dragging a file onto the node. The four x/y widgets exist for wiring and for API use; normal human usage is dragging the box. Advanced users can drive them from other nodes if they want a scripted crop.

    Outputs:

    • image - the cropped image tensor (BHWC, like any ComfyUI IMAGE).
    • mask - the cropped alpha mask. Note the gotcha: this is the image's own transparency mask, same as stock LoadImage, not a "highlight the crop area" selection. On an opaque PNG it's all zeros, which is correct and not a bug.
    • width, height - the crop dimensions as INTs. Feed these into an Empty Latent Image, a KSampler resolution, or a resize node to keep downstream sizes consistent with the region you actually cut.

    Installing it

    Load Image Cropped ships in Pepehoschi/ComfyUI-PepeUtils (GPL-3.0). Install via ComfyUI Manager (search "ComfyUI-PepeUtils") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Pepehoschi/ComfyUI-PepeUtils
    

    Restart ComfyUI and you're done - no extra dependencies, just the torch/numpy/Pillow stack ComfyUI already runs.

    Gotchas

    If you reopen a saved workflow and the crop looks reset, the coordinates are just at their defaults - the full-image fallback means you get the whole picture rather than an error, so drag the box again. And remember the mask output reflects the file's alpha, not your selection. If you need a mask of the crop shape itself, generate one downstream; this node's mask is the load-side mask, cropped to match.

    It's a load node with a nicer crop UX. Put it at the front of any img2img, detailer, or ControlNet-region workflow and you stop leaving ComfyUI just to trim a picture.

    Categoryimage

    Inputs (5)

    NameTypeDefaultDescription
    imageCOMBO1 options: example.png
    x1INT0
    y1INT0
    x2INT0
    y2INT0

    Outputs (4)

    NameTypeDescription
    imageIMAGE
    maskMASK
    widthINT
    heightINT