Nodes/Best Resolution/Upscaled Crop/Pad (Best-Res)
ComfyUI Node

Upscaled Crop/Pad (Best-Res)

If the original resolution can't be scaled to the higher one uniformly (i.e., without stretching), this node detects the appropriate values for cropping/out-painting.

By Lex-DRL·Created about a year ago·Updated 4 months ago· 14
Upscaled Crop/Pad (Best-Res)
    • upscale
    • do_crop
    • crop_width
    • crop_height
    • crop_x
    • crop_y
    • do_padding
    • pad_left
    • pad_top
    • pad_right
    • pad_bottom
    upscale1.50
    init_width1024
    init_height1024
    HD_width1536
    HD_height1536
    strategypad only
    align_x0.500
    align_y0.000
    CategoryBest Resolution

    Inputs (8)

    NameTypeDefaultDescription
    upscaleFLOAT1.50Only used when <UpscaledCropPadStrategy.EXACT_UPSCALE: 'exact-upscale'> strategy selected.
    init_widthINT10241–9223372036854776000Width for original/initial image
    init_heightINT10241–9223372036854776000Height for original/initial image
    HD_widthINT15361–9223372036854776000Width for the (main/upscaled) HD-image
    HD_heightINT15361–9223372036854776000Height for the (main/upscaled) HD-image
    strategyCOMBOpad onlyIf the upscaled resolution can't be achieved by uniform scaling of the initial-res, how to tweak the image to get there: • pad only - upscale the image to fit it into the desired frame on one side, then add missing pixels on the other one for outpaint. • crop only - upscale the image to fill the entire frame, then crop extra pixels on one side. • nearest - automatically choose one of the above, to crop/pad the least number of pixels (by area). • exact-upscale - follow the provided upscale-value precisely. This is the only option that uses it. Also, it's the only one that might require both outpainting and crop. In case when both are required, the output values assume this order: upscale -> crop -> pad.
    align_xFLOAT0.5000–1Where's the image pivot for horizontal alignment (which side stays in place during crop/out-paint): 0 - Left 0.5 - Center 1 - Right
    align_yFLOAT0.0000–1Where's the image pivot for vertical alignment (which side stays in place during crop/out-paint): 0 - Bottom 0.5 - Center 1 - Top

    Outputs (11)

    NameTypeDescription
    upscaleFLOATThe actual uniform upscale value to do.
    do_cropBOOLEANWhether post-upscale crop needs to be done to get the specified resolution.
    crop_widthINTWidth for the post-upscale crop.
    crop_heightINTHeight for the post-upscale crop.
    crop_xINTX-offset for the post-upscale crop.
    crop_yINTY-offset for the post-upscale crop.
    do_paddingBOOLEANWhether post-upscale padding and out-paint need to be done to get the specified resolution.
    pad_leftINTLeft padding for the post-upscale out-paint.
    pad_topINTTop padding for the post-upscale out-paint.
    pad_rightINTRight padding for the post-upscale out-paint.
    pad_bottomINTBottom padding for the post-upscale out-paint.