Nodes/comfyui-AGSoft/🖼️AGSoft Image & Mask Resize
ComfyUI Node

🖼️AGSoft Image & Mask Resize

Resize image and mask together — proportions preserved, edges intact

By Art-xmaster·Created 12 months ago·Updated a day ago· 23
🖼️AGSoft Image & Mask Resize
  • input_image
  • mask
  • image
  • mask
  • width
  • height
  • filename
  • filepath
custom_path
image
resize_modetarget_percentage
target_percentage100.0
target_megapixels1.0
target_width1024
target_height1024
fit_modecrop
crop_positioncenter
interpolationlanczos
resize_if_largernone
resize_if_smallernone
pad_image_colorwhite
pad_mask_colorblack
invert_maskfalse
flip_modenone
angle_degrees0
rotation_presetnone
divisible_by0
devicecpu

The difference between a useful mask node and an annoying one is whether the mask stays in sync with the image. AGSoft Image & Mask Resize is the lean version of the pack's resize family: feed it an image and a mask, tell it a size, and both come out resized together, with the mask keeping hard edges instead of turning into gray mush. It's the node you reach for when the fancy "Plus" version is overkill but you still don't want to resize image and mask separately.

How it works

One size spec, applied to both. resize_target picks the anchor axis - width or height. Then size is the target value on that axis (set to 0 to ignore it), and the other dimension scales to keep proportions. Leave size at 0 and scale_by takes over: 1.0 is unchanged, 0.5 halves, 2.0 doubles. Whichever way you go, the aspect ratio is preserved - no stretching.

Two details in the implementation matter in practice:

  • divisible_by (default 8) - the final dimensions get rounded up to a multiple. Feed this into an SD or SDXL sampler and you sidestep the "not divisible" errors before they happen.
  • Mask resampling is nearest-neighbor - while the image uses the upscale_method you picked (lanczos, bicubic, etc.), the mask is resized with nearest, so a crisp mask stays crisp. A blurred mask in a workflow is almost always someone resizing it with bilinear.

invert_mask flips black/white if your mask happens to be stored inverted, and device lets you pin the work to CPU or CUDA (it auto-falls back to CPU when CUDA isn't available).

Inputs and outputs

Required inputs: image, mask, resize_target, size, scale_by, upscale_method, invert_mask, divisible_by, device. Outputs: the resized image, the resized mask, and width/height ints for downstream nodes. Batches are handled - a single mask gets repeated to match a batch of images.

Where you'd use it

Classic case: you have a source image and a hand-painted mask at a different resolution (say the mask was drawn at preview size), and you need both at a common size before sampling. Also the standard pre-step for inpainting: resize the pair to a model-friendly resolution so the mask lines up with what the sampler actually sees. And in image-to-image work where you want a smaller latent but a full-res mask for the final composite - this keeps them matched.

Installing it

Pack standard: ComfyUI Manager → search comfyui-AGSoft → install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/Art-xmaster/comfyui-AGSoft.git

No models, no dependencies beyond ComfyUI's built-ins.

Common issues

The two things that bite: forgetting that size beats scale_by when both are set (it's size-first logic), and expecting bilinear-smooth masks. If your mask comes back blocky, that's intentional - nearest is the right choice for mask edges, and you can soften it downstream with a blur if a specific model needs it. Also remember rounding is up to the divisible_by multiple, so a 500px target at divisible_by 8 becomes 504, not 496 - worth knowing if you're matching an exact pixel budget from another node.

CategoryAGSoft/Image

Inputs (22)

NameTypeDefaultDescription
custom_pathSTRINGOptional: absolute path to an image (or a linked string). Priority: input_image > custom_path > image combo. --- Опционально: абсолютный путь к изображению (или линк со строкой). Приоритет: input_image > custom_path > комбо image.
imageCOMBOSelect an image from the input directory (used when input_image is not connected and custom_path is not set). --- Выберите изображение из папки input (используется, если не подключён input_image и не задан custom_path).
resize_modeCOMBOtarget_percentageSize mode: percentage / megapixels / width / height / both / longest / shortest. --- Режим размеров: проценты / мегапиксели / ширина / высота / оба / longest / shortest.
target_percentageFLOAT100.00–1000Target size as % of original (100=same, 50=half, 200=double). --- Целевой размер в % от исходного (100=тот же, 50=половина, 200=двойной).
target_megapixelsFLOAT1.00.1–100Target megapixels (MP). Used in target_megapixels mode. --- Целевые мегапиксели (MP). Используется в режиме target_megapixels.
target_widthINT10241–8192Target width (px). Also = the side for longest/shortest modes. --- Целевая ширина (px). Также = сторона для longest/shortest.
target_heightINT10241–8192Target height (px). --- Целевая высота (px).
fit_modeCOMBOcropScaling strategy: stretch (distort to exact target) / crop (proportional cover + cut) / pad (proportional contain + bars) / proportional (proportional fit inside the target, output = resulting size, no bars, no crop). --- Стратегия: stretch (искажить в точную цель) / crop (пропорционально закрыть и обрезать) / pad (пропорционально вписать с полями) / proportional (пропорционально вписать в цель, выход = получившийся размер, без полей и обрезки).
crop_positionCOMBOcenterAnchor for crop/pad (9 positions). --- Якорь для crop/pad (9 позиций).
interpolationCOMBOlanczosInterpolation. RGBA auto-uses premultiplied alpha. --- Интерполяция. RGBA автоматически с premultiplied alpha.
resize_if_largerCOMBOnonePure trigger: resize ONLY if the image is LARGER than target; otherwise the original size is kept. Triggered → resize per fit_mode. none = always resize. --- Чистый триггер: ресайз ТОЛЬКО если изображение БОЛЬШЕ цели, иначе сохраняется исходный размер. Сработало → ресайз по fit_mode. none = ресайз всегда.
resize_if_smallerCOMBOnonePure trigger: resize ONLY if the image is SMALLER than target; otherwise the original size is kept. Triggered → resize per fit_mode. none = off. --- Чистый триггер: ресайз ТОЛЬКО если изображение МЕНЬШЕ цели, иначе сохраняется исходный размер. Сработало → ресайз по fit_mode. none = выкл.
pad_image_colorCOMBOwhitePadding color for the image (pad). --- Цвет полей изображения (pad).
pad_mask_colorCOMBOblackPadding color for the mask (pad). --- Цвет полей маски (pad).
invert_maskBOOLEANfalseInvert the mask before processing. --- Инвертировать маску перед обработкой.
flip_modeCOMBOnoneMirror AFTER resize: none / horizontal / vertical. --- Отражение ПОСЛЕ ресайза: none / horizontal / vertical.
angle_degreesINT0-360–360Rotation angle (counter-clockwise), applied BEFORE resize. --- Угол поворота (против часовой), до ресайза.
rotation_presetCOMBOnoneQuick angle; overrides angle_degrees. --- Быстрый угол; переопределяет angle_degrees.
divisible_byINT00–128Round sizes to a multiple (0=off). --- Кратность размеров (0=выкл).
deviceCOMBOcpuCompute device: cpu / cuda. --- Устройство: cpu / cuda.
input_imageoptIMAGEOptional image tensor (priority over the file combo). --- Опциональный тензор изображения (приоритет над файловым комбо).
maskoptMASKOptional input mask (priority over the alpha-derived mask). --- Опциональная входная маска (приоритет над альфа-маской).

Outputs (6)

NameTypeDescription
imageIMAGE
maskMASK
widthINT
heightINT
filenameSTRING
filepathSTRING