Nodes/comfyui_my_img_util/Image Trim Edges
ComfyUI Node

Image Trim Edges

Shave the border off any image, in pixels or percent

By sugarkwork·Created about a year ago·Updated 7 months ago· 2
Image Trim Edges
  • image
  • image
top0.0
bottom0.0
left0.0
right0.0
is_pixeltrue

A surprisingly large chunk of ComfyUI post-processing is "cut stuff off the edge". Watermark bars, letterbox bars, overscan from an upscaler, black edges left by a rotation, a strip of haloing artifacts along a batch of frames. Image Trim Edges is the no-frills node for that: give it the four edges you want to lose, in pixels or percent, and it hands back the shaved image. It won't resize, recenter, or get clever - it just trims.

How it works

It's a tensor slice. The node takes your top, bottom, left, right values and cuts those amounts off the four edges. With is_pixel on, the values are pixels (truncated to integers, so fractional values floor down). With it off, they're percent of the image's height for top/bottom and width for left/right, capped at 99% so you can't accidentally delete the whole image. And if your trim totals would collapse an axis entirely - top + bottom ≥ height, say - the node silently resets that axis to zero rather than erroring.

That last behavior is worth internalizing: this node won't crash, it just won't do what you asked. Trim 60% off the top and 60% off the bottom and you get... no trim on that axis. No error, no warning. If the output looks untrimmed, check your numbers.

The inputs and outputs that matter

  • image - the IMAGE to trim.
  • top, bottom, left, right - FLOAT amounts, default 0, minimum 0. Pixels or percent depending on is_pixel.
  • is_pixel - BOOLEAN, default true. On = pixel values; off = percent.

Output: image, the trimmed IMAGE. Note the output is smaller than the input - that's the point - but it means anything downstream that assumed a fixed canvas will see a different shape unless your trim amounts are fixed too.

Installing it

One pack, same drill as the rest of comfyui_my_img_util. ComfyUI Manager → search "comfyui_my_img_util", or:

cd ComfyUI/custom_nodes
git clone https://github.com/sugarkwork/comfyui_my_img_util
cd comfyui_my_img_util
pip install -r requirements.txt

Restart. Dependencies are numpy, Pillow, and opencv-python - the OpenCV dependency exists for the pack's denoise node, but since nodes.py imports cv2 at module level, every node in the pack (this one included) fails to load if you skip the pip install. No model files, no downloads, nothing GPU-heavy.

Common issues

  • Trimmed nothing, or trimmed everything. Check is_pixel first. A value of 50 on a 2048px image is a barely-visible sliver; 50 as percent is a huge cut. Percent is more portable when your input sizes vary; pixels are more predictable.
  • Silent no-op when trims collide. As above: trim totals that would collapse an axis get reset to zero with no error. The guard keeps the node alive, but it reads like "broken" if you don't know it's there.
  • Floating-point expectations. The UI accepts 12.5, but pixel mode truncates to 12. Fine for everything except the person who needs sub-pixel offset accuracy, which is not a real use case.

Where you'd actually use it

Removing the edge artifacts that video models like AnimateDiff and Wan leave on frames after rotation. Chopping the bars off a 16:9 render you're re-framing. Stripping a fixed margin off a whole training batch before labeling. For trimming the same amount off every frame of a video, this beats any model pass by orders of magnitude - it's a slice operation, deterministic, instant. Pair it with Image Resize And Crop from the same pack and you've got a two-node "normalize anything to anything" chain: trim the junk, then cover-crop to a fixed canvas.

Categoryimage

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
topFLOAT0.0
bottomFLOAT0.0
leftFLOAT0.0
rightFLOAT0.0
is_pixelBOOLEANtrue

Outputs (1)

NameTypeDescription
imageIMAGE