π FRED Auto Crop Image Native Ratio
Crop anything to a native SDXL ratio without cutting your subject off
- image
- preview_mask_color
- mask_optional
- modified_image
- preview
- modified_mask
- scale_factor
- output_width
- output_height
- native_width
- native_height
- sd_aspect_ratios
- help
Every diffusion model has native resolutions it was trained on, and SDXL especially was trained on a discrete set of aspect ratios. Feed it something off-ratio and you get stretched bodies, doubled limbs, repeated patterns. That's exactly the problem FRED_AutoCropImage_Native_Ratio exists to kill: it takes whatever image you throw at it, crops it to a proper SD/SDXL ratio, and - here's the part that makes it worth reaching for - it can preserve a mask so the crop doesn't lop your subject's head off.
What it actually does
It ships with a baked-in table of 25 standard ratios, from 5:12 portrait (640x1536) up to 12:5 ultra-wide (1536x640), plus square 1:1. You have three broad modes on the aspect_ratio dropdown:
- Auto_find_resolution - it picks the closest native ratio to your input image. Zero thought required.
- A named ratio like
3:4 portrait 768x1024- force that exact one. - custom - use the
custom_width/custom_heightinputs instead.
On top of the ratio crop you get the useful extras. mask_preserve keeps the area under mask_optional inside the final crop, which is the killer feature for faces or products - feed a subject mask in and it slides the crop window so nothing important gets cut. Precrop_from_input_mask is different: it crops the image down to the mask's boundaries first, then applies the ratio crop, which is handy when your source is a big scene and you only care about the masked region. crop_x_in_Percent / crop_y_in_Percent shift the crop window off-center when you want a subject kept at a specific spot.
Then there's the resize half. resize_image turns on scaling to the target dimensions, with separate interpolation choices for upscale (bilinear default) and downscale (area default - that's the right pick, area is what you want when shrinking). multiple_of rounds the result to a multiple of 2/4/8/16/32/64, which matters because many upscale models and some samplers are happiest on multiples of 8. prescale_factor scales before cropping when enabled, useful when the source is small.
The outputs you'll actually use
modified_image- your cropped (and optionally resized) result, straight into a KSampler or a save node.modified_mask- the mask transformed to match the new crop, so downstream inpainting/Detailer-style passes line up.scale_factor,output_width,output_height,native_width,native_height- bookkeeping;scale_factoris the one worth wiring if you're feeding an upscaler.preview- the crop with a colored mask overlay, so you can eyeball where it's about to cut before you commit.
sd_aspect_ratios is just the list of ratios as text. And like every node in this pack, there's a help output that dumps the whole reference card into a text box.
Installing it
It ships in the FRED Nodes v2 pack, so install once and every πFRED node shows up under a πFRED menu:
cd ComfyUI/custom_nodes
git clone https://github.com/Poukpalaova/ComfyUI-FRED-Nodes_v2.git
Then restart ComfyUI (or hit Refresh). You can also search "ComfyUI FRED Nodes v2" in ComfyUI Manager. The pack pulls in opencv-python, numpy, Pillow and a git dependency on ocampor/image-quality, so give the install a moment.
Gotchas
Mask inputs need to match the image's spatial dimensions; the mask output only makes sense if you fed a mask in. And remember mask_preserve is a constraint, not a guarantee - if your target ratio is far enough from the source, something has to give, so pick a closer ratio or let Auto_find do it.
Inputs (18)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | β | |
| Precrop_from_input_mask | BOOLEAN | false | β |
| aspect_ratio | COMBO | Auto_find_resolution | 28 options: custom, Auto_find_resolution, 5:12 portrait 640x1536, 9:21 portrait 576x1344, 1:2 portrait 768x1536, 9:16 portrait 768x1344, +22 |
| mask_preserve | BOOLEAN | false | β |
| custom_width | INT | 102464β8192 | β |
| custom_height | INT | 102464β8192 | β |
| crop_from_center | BOOLEAN | true | β |
| crop_x_in_Percent | INT | 00β100 | β |
| crop_y_in_Percent | INT | 00β100 | β |
| resize_image | BOOLEAN | false | β |
| resize_mode_if_upscale | COMBO | bilinear | 5 options: bicubic, bilinear, nearest, nearest-exact, area |
| resize_mode_if_downscale | COMBO | area | 5 options: bicubic, bilinear, nearest, nearest-exact, area |
| prescale_factor | FLOAT | 1.50.1β8 | β |
| include_prescale_if_resize | BOOLEAN | false | β |
| multiple_of | COMBO | 1 | 7 options: 1, 2, 4, 8, 16, 32, +1 |
| preview_mask_color_intensity | FLOAT | 0.40.1β1 | β |
| preview_mask_color | COLOR | #503555 | β |
| mask_optionalopt | MASK | β |
Outputs (10)
| Name | Type | Description |
|---|---|---|
| modified_image | IMAGE | β |
| preview | IMAGE | β |
| modified_mask | MASK | β |
| scale_factor | FLOAT | β |
| output_width | INT | β |
| output_height | INT | β |
| native_width | INT | β |
| native_height | INT | β |
| sd_aspect_ratios | STRING | β |
| help | STRING | β |