Nodes/ComfyUI FRED Nodes v2/πŸ‘‘ FRED Auto Crop Image Native Ratio
ComfyUI Node

πŸ‘‘ FRED Auto Crop Image Native Ratio

Crop anything to a native SDXL ratio without cutting your subject off

By PoukpalaovaΒ·Created about a year agoΒ·Updated 7 months agoΒ· 3
πŸ‘‘ FRED Auto Crop Image Native Ratio
  • 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
β—„Precrop_from_input_maskfalseβ–Ί
β—„aspect_ratioAuto_find_resolutionβ–Ί
β—„mask_preservefalseβ–Ί
β—„custom_width1024β–Ί
β—„custom_height1024β–Ί
β—„crop_from_centertrueβ–Ί
β—„crop_x_in_Percent0β–Ί
β—„crop_y_in_Percent0β–Ί
β—„resize_imagefalseβ–Ί
β—„resize_mode_if_upscalebilinearβ–Ί
β—„resize_mode_if_downscaleareaβ–Ί
β—„prescale_factor1.5β–Ί
β—„include_prescale_if_resizefalseβ–Ί
β—„multiple_of1β–Ί
β—„preview_mask_color_intensity0.4β–Ί

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_height inputs 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_factor is 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.

CategoryπŸ‘‘FRED/image/postprocessing

Inputs (18)

NameTypeDefaultDescription
imageIMAGEβ€”
Precrop_from_input_maskBOOLEANfalseβ€”
aspect_ratioCOMBOAuto_find_resolution28 options: custom, Auto_find_resolution, 5:12 portrait 640x1536, 9:21 portrait 576x1344, 1:2 portrait 768x1536, 9:16 portrait 768x1344, +22
mask_preserveBOOLEANfalseβ€”
custom_widthINT102464–8192β€”
custom_heightINT102464–8192β€”
crop_from_centerBOOLEANtrueβ€”
crop_x_in_PercentINT00–100β€”
crop_y_in_PercentINT00–100β€”
resize_imageBOOLEANfalseβ€”
resize_mode_if_upscaleCOMBObilinear5 options: bicubic, bilinear, nearest, nearest-exact, area
resize_mode_if_downscaleCOMBOarea5 options: bicubic, bilinear, nearest, nearest-exact, area
prescale_factorFLOAT1.50.1–8β€”
include_prescale_if_resizeBOOLEANfalseβ€”
multiple_ofCOMBO17 options: 1, 2, 4, 8, 16, 32, +1
preview_mask_color_intensityFLOAT0.40.1–1β€”
preview_mask_colorCOLOR#503555β€”
mask_optionaloptMASKβ€”

Outputs (10)

NameTypeDescription
modified_imageIMAGEβ€”
previewIMAGEβ€”
modified_maskMASKβ€”
scale_factorFLOATβ€”
output_widthINTβ€”
output_heightINTβ€”
native_widthINTβ€”
native_heightINTβ€”
sd_aspect_ratiosSTRINGβ€”
helpSTRINGβ€”