Resize image to square
Cropping to a square without doing the math yourself
- image
- ui_widget
- image
- image_list
- count
Plenty of things downstream want a square input - thumbnail grids, certain analyzers, some training pipelines - and your source image almost never arrives that way. LF_ResizeImageToSquare handles the crop-and-resize math in one node instead of you chaining a crop node into a resize node and eyeballing the offsets.
It works in two steps under the hood: crop the image to a square aspect ratio using whichever crop_position you choose, then resize that square to your target square_size (default 1024px) with the resampling algorithm set in resize_method. crop_position picks which part of the original image survives the crop - center is the safe default, but top, bottom, left, or right matter if your subject isn't centered and you'd rather crop out the far edge than the subject's face. resize_method gives you the usual resampling tradeoff: bicubic (the default) is the smooth, general-purpose choice; nearest and nearest exact preserve hard edges and are the ones you want for pixel art or masks where smoothing would blur data you actually need intact; bilinear and linear sit in between.
You get three outputs back: image, the square result; image_list, the same thing as a list (useful if you fed a batch in and want it addressable as separate items downstream); and count, how many images came out. There's also an optional ui_widget slot rendering a tree view on the node - that's display only, nothing to configure there.
Installing it. Search "LF Nodes" in ComfyUI Manager and install, or clone manually: cd ComfyUI/custom_nodes && git clone https://github.com/lucafoscili/lf-nodes, then restart ComfyUI. Use that URL - the pack's original home, comfyui-lf, is the one linked from comfy.icu's node listing, but it's archived; the author moved active development to lf-nodes a while back and the old repo won't see fixes. No model downloads, no heavy dependencies - this is a pure image-processing utility.
Where people get tripped up. The obvious one: this crops, it doesn't pad or letterbox. If your subject fills the frame edge to edge and you crop from a non-square source, you will lose content on whichever side gets trimmed - pick your crop_position deliberately rather than leaving everything at center by habit. Second, resample method choice matters more than people expect on downscales: if your output looks softer than the source, you're probably on bicubic when you wanted a sharper method, or vice versa if you're seeing jagged edges you didn't want. And if you need aspect-preserving resize instead of a hard square crop, this is the wrong node entirely - LF_ResizeImageByEdge, from the same pack, is built for that.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Input image tensor or a list of image tensors. | |
| square_size | INT | 1024 | The length of the square's edge. |
| resize_method | COMBO | bicubic | Resampling method for resizing. |
| crop_position | COMBO | center | Where to crop the image. |
| ui_widgetopt | KUL_TREE | [object Object] | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| image_list | IMAGE | — |
| count | INT | — |