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

🖼️AGSoft Load Image & Mask Resize

Resize image and mask together, or watch your inpaint drift

By Art-xmaster·Created about a year ago·Updated a day ago· 25
🖼️AGSoft Load 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 classic way to quietly ruin an inpainting workflow is to upscale the image with one node, upscale the mask with another, and hope they still line up. Two independent interpolation passes, and by the time you've thrown in a crop or pad you're a few pixels off - which shows up as seams, or as the sampler regenerating a region you meant to keep. AGSoft Load Image & Mask Resize is the "do it in one place" version: it loads an image and its mask, then runs rotate → resize → flip over both as a single synchronized unit. They can't drift apart because they share one code path.

You'd reach for it at the front of an inpaint or outpaint pipeline, when you need to get a source image onto a model's native resolution and into a latent-friendly shape before anything else runs. It's also the right tool when the resize has conditions on it - "only shrink if it's bigger than the target," say - because those live in the same node instead of a hand-rolled If block.

Sources, in priority order

  • input_image (optional) - an image tensor from another node, highest priority.
  • custom_path - absolute path or linked string, next in line, validated at connect time.
  • image - the combo/upload widget, used when neither of the above is set.

That first option is what separates this from the plain load node: you can chain it after any node that emits an IMAGE and never touch disk.

The inputs that actually matter

The node has a lot of knobs; these are the ones a beginner sets:

  • resize_mode - seven ways to express the target: target_percentage, target_megapixels, target_width, target_height, target_both, target_longest, target_shortest. Megapixels mode is genuinely handy when you care about total pixel budget (upscaling) rather than exact dimensions.
  • fit_mode - this owns how it resizes: stretch (distort to the exact target), crop (scale proportionally, cut the overflow), pad (scale to fit, fill bars), proportional (fit inside the target and output the resulting size - no bars, no crop).
  • resize_if_larger / resize_if_smaller - pure triggers that decide whether to resize at all, independent of fit_mode. Set to none means always resize; otherwise the original size is kept when the condition doesn't fire. Pair these with fit_mode and you get conditional resizing without extra nodes.
  • crop_position - nine anchors for where crop/pad cuts or pads.
  • divisible_by - rounds the output dimensions to a multiple. Set 16 for SDXL, 8 for Flux; 0 is off. This is the one that stops the "latent size mismatch" error before it happens.

Worth knowing: interpolation defaults to lanczos, and for RGBA images the node auto-applies premultiplied alpha so resizing transparency doesn't give you that ugly dark halo. Rotation via angle_degrees (or the rotation_preset quick angles, which override the degrees field) runs before resize; flip_mode after. There's invert_mask if your mask convention is backwards, and device toggles CPU/CUDA - leave it on CPU unless you're doing huge batches, resizing is not the bottleneck.

Outputs are the same six as the plain loader: image, mask, width, height, filename, filepath - so it slots into any workflow that expected a load node.

Install

Same pack as everything AGSoft - the ComfyUI Manager route or the manual clone:

# ComfyUI Manager: search "comfyui-AGSoft" and install
# or:
cd ComfyUI/custom_nodes
git clone https://github.com/Art-xmaster/comfyui-AGSoft.git
# restart ComfyUI

Dependencies are light (numpy, opencv-python, translators) and this node needs no model files. Find it under AGSoft/Image in the node menu.

Gotchas

  • A custom_path typo fails at connect time, not at run - that's the node doing its job, but it means a string from another node that's empty will fall back to the combo rather than error. Check your wiring if the "wrong" image loads.
  • Mask too clean to be true? If nothing is connected and the source has no alpha, the mask output is all zeros. Fine for a plain resize, useless for inpainting - connect a real mask or feed it a transparent PNG.
  • The README is Russian-first and detailed node docs live on the author's Telegram channel; the in-node tooltips are bilingual, so start there.
CategoryAGSoft/Image

Inputs (22)

NameTypeDefaultDescription
custom_pathSTRINGOptional: absolute path to an image (or a linked string). Priority: input_image > custom_path > image combo. The native preview follows it (live when typed, after execution when linked). --- Опционально: абсолютный путь к изображению (или линк со строкой). Приоритет: input_image > custom_path > комбо image. Нативное превью следует за ним (живо при вводе, после выполнения — если линком).
imageCOMBOSelect / upload an image from the input directory (used when input_image is not connected). --- Выберите / загрузите изображение из папки input (используется, если не подключён input_image).
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