Nodes/ComfyUI-SmartCrop/πŸ“ ImageSmartCrop
ComfyUI Node

πŸ“ ImageSmartCrop

A crop that doesn't behead your subject

By turkydenΒ·Created 2 years agoΒ·Updated 2 years agoΒ· 4
πŸ“ ImageSmartCrop
  • image
  • image
β—„width1024β–Ί
β—„height1024β–Ί

Here's the problem ImageSmartCrop solves: you've got an image with the subject sitting anywhere but dead center, you resize or crop it, and the subject's head ends up on the cutting room floor. A center crop has no idea your face is off to the left. This node doesn't guess - it looks at the whole image, decides where the interesting stuff actually is, and crops there. The name isn't hype; it's the honest description.

One thing up front: this is not ML. It needs no model, no GPU, no API key. It's a ComfyUI wrapper around smartcrop.py, the Python port of the decade-old smartcrop.js algorithm that photo tools have quietly used for years. And it's the entire contents of the turkyden/ComfyUI-SmartCrop pack - one node, a vendored copy of the algorithm, and a dependency list that's just Pillow.

How it actually works

The core is a scoring pass over candidate crops. The algorithm shrinks your image, then slides a window around at 8-pixel steps at a few scales, and gives every candidate a score made of four things:

  • Skin detection - weighted the heaviest (1.8 vs. everything else's fractions), because a frame that contains faces is almost always the frame you want.
  • Edge detection - sharp detail reads as "in focus," so the crop is drawn to crisp regions, not the blurred background.
  • Saturation - vivid, colorful areas pull the crop toward them.
  • Rule of thirds - the classic composition heuristic nudges the box so the subject isn't smack in the middle like a mugshot.

The highest-scoring box wins, gets cropped out, and is then scaled to your target size with Lanczos. It's the same trick birme.net's "auto focal point" uses, and it's genuinely good at keeping a subject intact where a center crop would amputate.

The inputs and outputs that matter

The node is refreshingly short on knobs:

  • image (IMAGE) - whatever you're feeding in.
  • width / height (INT, 0–2048, default 1024) - the target crop size. These are the only two you'll touch: want a 16:9 video thumbnail? Set 1920Γ—1080. Prepping square training images? 512Γ—512.

Output is a single image (IMAGE) that wires straight into anything downstream - a ControlNet preprocessor, a VAE encode, an upscaler input, or a batch of training crops. If you're prepping a dataset, this is the node that saves you from the classic "center-crop decapitated half my photos" complaint.

Installing it

The README is minimal, so here's the whole story. In ComfyUI Manager, search "SmartCrop" and install. Or, old-school:

cd ComfyUI/custom_nodes
git clone https://github.com/turkyden/ComfyUI-SmartCrop

Then restart ComfyUI. No model files to fetch, no heavy dependencies - the only declared requirement is Pillow==10.3.0, which ComfyUI already ships with. That hard pin is the one thing to keep an eye on: if pip ever tries to downgrade your Pillow to satisfy it and something else breaks, that pin is the culprit.

Where people get burned

  • It only shrinks, never upscales. The final step is a PIL thumbnail(), which won't enlarge. Feed it a 512px source and ask for 2048Γ—2048 and you'll get 512 back. If you want more pixels, crop here, then feed the result into a real upscaler - this node is a crop, not a generative upscaler, and it won't invent detail.
  • It's a heuristic, not a face detector. Skin weighting dominates, so faces usually win - but a small, oddly lit, or heavily filtered subject can still lose. For perfect portrait framing you'd want something that detects faces explicitly.
  • Very large sources crawl. The algorithm is old-school and scans a lot of candidate boxes; it prescales to stay fast at normal sizes, but a 4K-plus source will make it feel sluggish.

It's a niche tool, and it knows it. But when the alternative is hand-cropping a batch of images or watching a center crop take your subject's head off, that niche is a comfortable place to stand.

CategoryπŸ‘½ ComfyLab/πŸ“ SmartCrop 智能裁ε‰ͺ

Inputs (3)

NameTypeDefaultDescription
imageIMAGEβ€”
widthINT10240–2048β€”
heightINT10240–2048β€”

Outputs (1)

NameTypeDescription
imageIMAGEβ€”