Nodes/Comfy_Felsirnodes/Focal Rescale
ComfyUI Node

Focal Rescale

Crop to fit without slicing the subject in half

By Felsir·Created 3 years ago·Updated about a year ago· 23
Focal Rescale
  • image_in
  • IMAGE
  • rect_left
  • rect_top
  • rect_width
  • rect_height
width512
height512
focalx256
focaly256

Focal Rescale is the flagship node of this pack, and the reason the pack exists at all. It changes an image's aspect ratio by cropping around a point you choose - so the thing you care about survives the crop, and the result is resized to your target width and height without being squashed or stretched.

The author's own origin story: he was tweaking img2img workflows and wanted to turn any source image into a 16:9 diffusion canvas without building a tangle of math nodes, so he wrote this and posted it to r/comfyui. The README's classic example says it all: a moon sitting at pixel (600,100) in a big source image, rescaled to 800x200 and 512x768 - the moon stays in frame in both, because the crop was built around it rather than around the image's center.

How it works

The mechanism, from the code rather than the docs: you give it a target width and height. It computes the target aspect ratio, then finds the largest rectangle with that ratio that fits entirely inside the source image. That rectangle is centered on your focal point; if centering would shove an edge outside the image, the rectangle is clamped back in. Then it crops that rectangle and resizes it to exactly the target size.

That's the whole cleverness: it takes the maximum rectangle from the source, not just whatever fits around the focal point, so you keep the most image area possible. And it's all plain PIL pixel math - no diffusion, no models, nothing to download.

The inputs that matter

  • width / height - your output canvas, 16 to 2048.
  • focalx / focaly - the point in the source image's pixel coordinates you want centered. The defaults are 256,256, which is top-left-ish on most images: change them. If you'd rather not hand-pick them, that's exactly what the pack's Focalpoint from SEGS node is for - feed it a face detection and wire its X/Y straight in.

Outputs: the resized IMAGE, plus rect_left / rect_top / rect_width / rect_height - the crop rectangle in source coordinates. Those matter more than they look: if you're cropping a matching mask or depth map with the same geometry, you can feed the same four numbers into another crop and keep everything aligned.

Where it fits

It's the "crop" half of the detect-crop-refine loop from the Impact Pack world (the same one masking-detection-detailing.md describes) - without a detailer attached. Pair it with a face detector and you get automatic framing for a detail pass or an img2img regeneration.

Gotchas, learned the hard way

This node is built for single images. The multi-image batch path in this pack's crop nodes is not something to trust - feed one image at a time, or loop over your batch yourself. And keep expectations honest: it's a plain PIL resize, fine for pre- and post-processing, not a detail-adding upscaler. If your crop keeps landing wrong, suspect the focal point before the node - with the rectangle clamped to the image bounds, an extreme focal point just silently degrades into an edge crop.

Installing it

The pack has zero extra dependencies - pure PIL/numpy/torch, already in ComfyUI. ComfyUI Manager: search for Comfy_Felsirnodes (or "Felsir"), install, restart. Manual: cd ComfyUI/custom_nodes then git clone https://github.com/Felsir/Comfy_Felsirnodes, restart. The node lives under Add Node → Felsir.

CategoryFelsir

Inputs (5)

NameTypeDefaultDescription
image_inIMAGE
widthINT51216–2048
heightINT51216–2048
focalxINT256
focalyINT256

Outputs (5)

NameTypeDescription
IMAGEIMAGE
rect_leftINT
rect_topINT
rect_widthINT
rect_heightINT