ComfyUI Node

ratio_mask

A mask at exactly the ratio you asked for — with a matching preview image

By nerdywhiskers·Created 5 months ago·Updated 2 days ago· 1
ratio_mask
    • image
    • mask
    canvas width1024
    canvas height1024
    x512
    y512
    positionmiddle-center
    bg_color#000000
    corner_radius0
    blur0.0

    Most mask nodes give you a blob you drew by hand or a segmentation you had to argue with. ratio_mask is the opposite: you type 2.35:1 and get a white rectangle of exactly that aspect ratio, output as both an image and a mask. It's a utility, not a party trick, and it earns its place whenever a workflow needs a shape of a known proportion rather than a guess.

    Reach for it when you need letterbox bars at a film ratio, a composition frame at 16:9 inside a square canvas, a guide region for regional prompting, or a test card for "what does this look like at 1:1 vs 3:2" comparisons. Because it emits the image and the mask together, you can preview exactly what a blurred mask will do before you wire it into something destructive.

    How it works

    You give it width and height (the canvas), and ratio as free text - 1:1, 16:9, 2.35:1, decimals welcome. It parses the ratio, computes the largest rectangle of that aspect that fits inside the canvas minus the per-side padding_*, and places it at one of nine position slots. Then it renders two things: a MASK that's 1.0 inside the rectangle and 0.0 outside, and an IMAGE that paints white over your bg_color through that same mask. The blur is a Gaussian applied to the mask, and because the image is derived by alpha-blending through the blurred mask, soft edges look consistent in both outputs - no mismatch where the preview says feathered and the mask says hard.

    The inputs that matter

    • ratio - the whole point. 16:9, 2.35:1, 1:1, whatever. Invalid input (garbage text, a zero) silently falls back to 1:1, so typos show up as a square, not an error.
    • position - the same 9-grid as the pack's compose node: each slot centers the rectangle within a third of the canvas, not flush against a corner or edge.
    • corner_radius - rounds the corners in pixels, capped at half the shorter side. The cap means you can't turn a thin strip into an unreadable blob.
    • blur - feather the edges. This is where the IMAGE/MASK pairing pays off: crank it and watch the preview so the softness matches what your inpainting or compositing step expects.
    • bg_color - a hex string like #000000 (the default, for the classic white-on-black look) or #ffffff.

    Outputs are image (3-channel) and mask. Wire the mask into an inpainting or regional-conditioning setup, or save the image as a ratio guide.

    One honest limitation

    This is a rectangle generator, full stop. Rounded corners and blur are the only shape controls - there's no arbitrary polygon, no text, no positioning by pixel coordinate (the 9-grid is your placement). If you need a mask of a weird silhouette, this isn't it. What it's exceptionally good at is giving you a guaranteed ratio, which is precisely what hand-drawn masks and interpolation guesswork get wrong.

    Installing it

    Part of the Whisker pack, so the install is shared:

    cd ComfyUI/custom_nodes
    git clone https://github.com/nerdywhiskers/ComfyUI-Whisker-Nodes.git
    pip install -r ComfyUI-Whisker-Nodes/requirements.txt
    

    Or search "ComfyUI-Whisker-Nodes" in ComfyUI Manager and restart. You'll find it under Add Node → whisker-nodes. Pure Pillow/numpy - no model, no download, instant.

    Categorywhisker-nodes

    Inputs (8)

    NameTypeDefaultDescription
    canvas widthINT102416–8192
    canvas heightINT102416–8192
    xINT5121–8192Shape width in pixels (clamped to the canvas).
    yINT5121–8192Shape height in pixels (clamped to the canvas).
    positionCOMBOmiddle-center9 options: top-left, top-center, top-right, middle-left, middle-center, middle-right, +3
    bg_colorSTRING#000000
    corner_radiusFLOAT00–100Corner rounding as a percent of the maximum (half the shorter side). 100 draws an inscribed ellipse — a circle when x equals y.
    blurFLOAT0.00–200

    Outputs (2)

    NameTypeDescription
    imageIMAGE
    maskMASK