Image Crop Square
Square crop around the subject, without eyeballing it
- image
- mask
- image
Square crops are everywhere in this hobby - avatar prep, LoRA training thumbnails, before/after comparisons, "make this a 1:1" requests. Doing them by hand means guessing where the subject actually is. Image Crop Square centers the crop on your subject's mask instead: give it a mask of the thing you care about, and it returns a square crop framed around it, with padding and scaling you control.
It's from ComfyUI 1hewNodes (solo dev 1hew, bilingual README, active v3.x). The mask-guidance is what makes it worth reaching for over the stock crop node.
How it works
The node computes the bounding box of your mask, then builds a square around its center sized to the longer side of the bbox (so the whole subject fits). scale_factor expands or shrinks that framing, extra_padding adds an even border, and divisible_by snaps the final size to a multiple (8 by default) so your crop doesn't fight the latent space. If no mask is connected, it centers on the image instead - still square, still divisible.
The frame often extends past the image edges, which is where the fill comes in. The fill_color field doubles as a fill strategy: a plain color string fills the missing area, and the special keywords edge (sample the four image edges), average (average the whole image), and extend (stretch the edge pixels) make the padding look less like a matted box. With apply_mask on, the mask is used as a soft alpha when pasting the subject into the padded square - the crop region is masked instead of hard-rect.
The inputs that matter
- image - source image.
- mask - optional MASK that defines the subject. This is what centers the crop.
- scale_factor - 0.1–3, default 1. Framing zoom around the subject.
- extra_padding - border added around the square (default 0).
- fill_color - pad color, or a strategy keyword (
edge,average,extend). - apply_mask - use the mask as alpha when pasting the crop into the padded square.
- divisible_by - snap output size (default 8).
Output is a single image - the square crop, ready for VAE encode, training, or a preview.
Installing it
ComfyUI Manager → search "1hew" / "ComfyUI 1hewNodes" → install → restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes
First install is slow (the pack pulls opencv, scikit-image, scikit-learn, and detection deps like ultralytics/rembg for other nodes). No models for this node. Needs a current ComfyUI (modern node API - update if it doesn't register).
Gotchas
- No mask, surprising center - without a mask it just crops the image center. If your subject is off-center, connect a mask (or crop yourself).
apply_maskchanges semantics - with it on, the subject is composited with a soft mask edge into the padded canvas; with it off you get a hard rectangular crop. Different looks, same inputs.- Square ≠ your target ratio - this node only ever outputs 1:1. For 16:9 or arbitrary ratios use Image Crop With BBox Mask in the same pack.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| scale_factor | FLOAT | 1.000.1–3 | — |
| extra_padding | INT | 00–512 | — |
| fill_color | STRING | 1.0 | — |
| apply_mask | BOOLEAN | false | — |
| divisible_by | INT | 81–1024 | — |
| maskopt | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |