🖼️AGSoft Load Image & Mask Resize
Resize image and mask together, or watch your inpaint drift
- input_image
- mask
- image
- mask
- width
- height
- filename
- filepath
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 tononemeans always resize; otherwise the original size is kept when the condition doesn't fire. Pair these withfit_modeand 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_pathtypo 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.
Inputs (22)
| Name | Type | Default | Description |
|---|---|---|---|
| custom_path | STRING | Optional: 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. Нативное превью следует за ним (живо при вводе, после выполнения — если линком). | |
| image | COMBO | Select / upload an image from the input directory (used when input_image is not connected). --- Выберите / загрузите изображение из папки input (используется, если не подключён input_image). | |
| resize_mode | COMBO | target_percentage | Size mode: percentage / megapixels / width / height / both / longest / shortest. --- Режим размеров: проценты / мегапиксели / ширина / высота / оба / longest / shortest. |
| target_percentage | FLOAT | 100.00–1000 | Target size as % of original (100=same, 50=half, 200=double). --- Целевой размер в % от исходного (100=тот же, 50=половина, 200=двойной). |
| target_megapixels | FLOAT | 1.00.1–100 | Target megapixels (MP). Used in target_megapixels mode. --- Целевые мегапиксели (MP). Используется в режиме target_megapixels. |
| target_width | INT | 10241–8192 | Target width (px). Also = the side for longest/shortest modes. --- Целевая ширина (px). Также = сторона для longest/shortest. |
| target_height | INT | 10241–8192 | Target height (px). --- Целевая высота (px). |
| fit_mode | COMBO | crop | Scaling 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_position | COMBO | center | Anchor for crop/pad (9 positions). --- Якорь для crop/pad (9 позиций). |
| interpolation | COMBO | lanczos | Interpolation. RGBA auto-uses premultiplied alpha. --- Интерполяция. RGBA автоматически с premultiplied alpha. |
| resize_if_larger | COMBO | none | Pure 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_smaller | COMBO | none | Pure 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_color | COMBO | white | Padding color for the image (pad). --- Цвет полей изображения (pad). |
| pad_mask_color | COMBO | black | Padding color for the mask (pad). --- Цвет полей маски (pad). |
| invert_mask | BOOLEAN | false | Invert the mask before processing. --- Инвертировать маску перед обработкой. |
| flip_mode | COMBO | none | Mirror AFTER resize: none / horizontal / vertical. --- Отражение ПОСЛЕ ресайза: none / horizontal / vertical. |
| angle_degrees | INT | 0-360–360 | Rotation angle (counter-clockwise), applied BEFORE resize. --- Угол поворота (против часовой), до ресайза. |
| rotation_preset | COMBO | none | Quick angle; overrides angle_degrees. --- Быстрый угол; переопределяет angle_degrees. |
| divisible_by | INT | 00–128 | Round sizes to a multiple (0=off). --- Кратность размеров (0=выкл). |
| device | COMBO | cpu | Compute device: cpu / cuda. --- Устройство: cpu / cuda. |
| input_imageopt | IMAGE | Optional image tensor (priority over the file combo). --- Опциональный тензор изображения (приоритет над файловым комбо). | |
| maskopt | MASK | Optional input mask (priority over the alpha-derived mask). --- Опциональная входная маска (приоритет над альфа-маской). |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| width | INT | — |
| height | INT | — |
| filename | STRING | — |
| filepath | STRING | — |