AGSoft Image Resize MP
Resize by megapixels, not by guesswork
- image
- IMAGE
- width
- height
"How big is this image?" is a question people usually answer in megapixels, but resize nodes make you answer in width and height. AGSoft Img Res MP flips that: you say "1.0 MP" and it figures out the exact W×H to hit it while keeping your aspect ratio - then optionally rounds to a model-friendly multiple. It's the laziest way to standardize a bunch of differently-sized images before they hit a sampler or an upscale pass.
It's also the quiet workhorse of the pack's resize family: fewer knobs than the Resize Plus node, but for "make this a standard ~1MP" it's the one with the least friction.
How it works
Give it target_megapixels (default 1.0 - about 1000×1000 equivalent) and the node computes dimensions from the source's aspect ratio, then applies the other two settings that matter:
multiple_of- rounds the result to a multiple of 2/8/16/32/64/128 (default 0 = off). Turn on 64 for SDXL, 8 for SD1.5, and stop fighting sampler divisibility errors.fit_mode- what to do when rounding breaks the perfect aspect fit.pad(default) fits the whole image in the target box and fills the rest withpadding_color;cropfills the box and trims the overflow. Since rounding usually nudges the aspect slightly, this decides whether you lose pixels or gain a border.
position (default center) places the image within the padded box when fit_mode is pad - center, corners, or edges. interpolation defaults to lanczos, and area is the better pick for pure downscaling.
Inputs and outputs
Inputs: image, target_megapixels, interpolation, multiple_of, fit_mode, padding_color, position. Outputs: the resized image, plus width and height ints. Note there's no mask output here - if you need the mask resized to match, the Image & Mask Resize (or Resize Plus) nodes are the right choice. This one is purely about the image.
Where you'd use it
Three quick cases. Standardizing a batch of photos of wildly different resolutions before a grid or a dataset job. Prepping a source for a latent that expects ~1MP input. And as a cheap downscale stage: a soft 4K photo upscaled from a 0.35MP base - the community trick for sharp sources - is a target you can express directly in MP here.
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 extra dependencies - pure PIL/torch.
Common issues
The main gotcha is fit_mode defaulting to pad: if your source aspect doesn't match the rounded box, you get a border you didn't ask for - flip to crop when you want zero padding. And remember the pad happens after rounding, so a border may appear even at multiple_of 0 if the megapixel math lands on a non-integer. If your outputs are mysteriously a few pixels bigger than expected, rounding-up is doing its job; check multiple_of before suspecting a bug.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Входное изображение или батч изображений для изменения размера. | |
| target_megapixels | FLOAT | 1.00.01–50 | Целевое разрешение изображения в мегапикселях (MP). Например, 1.0 MP = 1000000 пикселей (примерно 1024x1024). |
| interpolation | COMBO | lanczos | Метод интерполяции при изменении размера: • nearest — самый быстрый, но низкое качество (пиксельный). • bilinear — сглаженный, быстрый, подходит для preview. • bicubic — более плавный, чем bilinear, хорош для фото. • area (BOX) — оптимален для уменьшения изображений (сохраняет детали). • lanczos — наивысшее качество, но медленнее; идеален для финального рендера. • nearest-exact — как 'nearest', но с улучшённой точностью (редко используется). |
| multiple_of | COMBO | 0 | Округляет итоговую ширину и высоту до кратного этому числу. 0 означает отключение. Полезно для совместимости с моделями (например, SDXL любит 1024, что кратно 64). |
| fit_mode | COMBO | pad | Стратегия обработки пропорций после округления до кратности: - 'crop': Обрезает изображение, чтобы заполнить всё пространство (может потерять края). - 'pad': Добавляет поля, чтобы всё изображение поместилось (без потерь). |
| padding_color | COMBO | black | Цвет полей при 'fit_mode=pad'. Для прозрачности изображение должно быть в формате RGBA (4 канала). |
| position | COMBO | center | Позиция изображения при 'fit_mode=pad' или 'fit_mode=crop'. Определяет, какая часть изображения будет видна после операции. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| width | INT | — |
| height | INT | — |