Nodes/ComfyUI_Crop_Image_By_Lightx02/Crop Image by Lightx02
ComfyUI Node

Crop Image by Lightx02

Crop Image by Lightx02

By Light-x02·Created about a year ago·Updated about a year ago· 1
Crop Image by Lightx02
  • image
  • mask
  • image
  • mask
crop_top0
crop_bottom0
crop_left0
crop_right0
rotation0

Most crop nodes in ComfyUI want a bounding box: feed in an x, a y, a width, a height, and hope you measured right. Crop Image by Lightx02 wants something dumber and often more useful - a pixel count to shave off each edge. Four numbers, no math about boxes, and it crops your image and its mask at the same time so the two never drift apart.

That last bit is the real reason to reach for it. Inpainting, masking, compositing - everywhere you keep a mask in lockstep with an image, this node keeps them aligned by construction, because both get the exact same crop in the same pass.

How it works

It's a single small Python file with zero custom dependencies - just numpy, Pillow, and torch, which ComfyUI already ships. Per frame, it converts the tensor to a PIL image, calls crop((left, top, right, bottom)) where left = crop_left, right = width - crop_right, and so on, then converts back. That's it. No magic, no model files, no auto-resize: what you crop is what comes out, at exactly the pixel size you trimmed it to.

It's also batch-aware. Feed it a stack of frames or a batch of upscaled tiles and each one gets the same trim, returned as a batch. So if you know every tile has 12 pixels of seam to shave, you can strip them all at once.

The README gives a nice worked example of the arithmetic: a 2600×1104 image, crop_left = 1352, crop_top = 136, crop_bottom = 136, crop_right = 0, and you get a 1248×832 region. It's all just subtraction - which is exactly why this node is handy for letterbox-bar trimming, where you know the bars are, say, exactly 136 pixels tall.

The inputs that matter

  • crop_top / crop_bottom / crop_left / crop_right - the whole show. Integers, 0–5000, pixels removed from each edge. 0 means "leave this edge alone."
  • rotation - a float from -180 to 180. Positive values rotate clockwise, despite the fact that PIL rotates counter-clockwise by default; the author negates the value internally so your intuition holds.

The image and mask are both optional inputs - wire in whatever you've got. The two outputs, image and mask, feed straight into the next node's matching sockets.

Installing it

Either open ComfyUI Manager and search "Crop Image by Lightx02", or:

cd ComfyUI/custom_nodes
git clone https://github.com/Light-x02/ComfyUI_Crop_Image_By_Lightx02

Restart ComfyUI and you're done. There's no requirements.txt, no model downloads, no heavy dependencies - one of those rare installs that just works.

Where people get burned

  • Rotation is a one-way street with consequences. expand=True means the canvas grows to fit the rotated image, and the corners get filled solid white (255 for masks). If you rotate 90°, your crop coordinates no longer describe the output, and there's no rotate-back here. Rotate last, or plan around it.
  • The outputs go None if their input is missing. Wire in only a mask and the image output is literally None, which silently breaks anything downstream expecting an image. If you don't need one of the pair, don't wire its output anywhere.
  • There's no clamp to the real dimensions. Crop values past the edge just clip silently, and if crop_left + crop_right exceeds the width you get an empty image and a confusing error two nodes later. The max of 5000 is a widget limit, not a check against your actual image size.
  • One global side effect: the module sets Image.MAX_IMAGE_PIXELS = None, which disables Pillow's decompression-bomb guard for your whole process. Mostly harmless, but know it's there if you're feeding untrusted giant images.

Honest bottom line: this is a tiny, quiet pack - barely a whisper of community presence, and the source is short enough to read in a minute. But it's clean, dependency-free, and genuinely the right tool for the narrow job it does. When you know your pixel counts and need the mask to follow along, it beats building the same thing out of core nodes.

CategoryLightx02

Inputs (7)

NameTypeDefaultDescription
crop_topINT00–5000
crop_bottomINT00–5000
crop_leftINT00–5000
crop_rightINT00–5000
rotationFLOAT0-180–180
imageoptIMAGE
maskoptMASK

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK