Load Image & Scale to Total Pixels
Loading and resizing to a target megapixel count in one step
- IMAGE
- MASK
Loading an image and resizing it to hit a specific pixel budget is normally two nodes: LoadImage, then something like ImageScaleToTotalPixels. This node does both in one - pick a file, set a target megapixel count, and out comes an image resized to match, plus its mask. The point isn't the resize itself, which core ComfyUI already does fine; it's not needing two nodes and a wire for something you'll do at the start of nearly every image-conditioned workflow.
Why "total pixels" instead of just width/height
Scaling to a total pixel count rather than a fixed width and height matters because it preserves the source image's aspect ratio while still giving downstream nodes a predictable amount of image to work with - which is what actually matters for VRAM and generation time, not the exact dimensions. This is also the exact preprocessing step behind a couple of upscaling tricks that are genuinely worth knowing: the community-standard advice for feeding a soft or already-low-detail source into a generative upscaler like SeedVR2 is to downscale it first - to around 0.35 megapixels - on the logic that there's no detail to recover at full resolution if the source is already soft, so you match it to its actual sharpness before letting the model rebuild from there. On the other end, people doing photo restoration pipelines scale up to around 4 megapixels before a detail pass, because pushing past that (8MP and beyond) tends to produce hallucinated detail rather than genuine restoration. This node is the tool for either move.
What matters
image(enum, required) - pick a file from your input directory, or selectnoneto skip loading entirely. Whennoneis chosen, both outputs come back empty.upscale_method(enum, required) -nearest-exact,bilinear,area,bicubic,lanczos. Lanczos is the one worth defaulting to for quality resizes; it's the community's go-to plain interpolation method and holds up well even against fancier generative options when you're not trying to add detail, just resize cleanly.megapixels(default1.0, range 0.01–16) - your target size in millions of pixels.1.0lands you around 1024×1024-equivalent depending on aspect ratio; adjust based on what you're feeding this into.bypass_sttp(BOOLEAN, defaultfalse) - skip the resize and pass the image (and mask) through at its original size.
Two outputs: IMAGE (loaded and scaled, or original if bypassed) and MASK (pulled from the alpha channel, scaled to match).
Installing it
Search ComfyUI-TkNodes in ComfyUI Manager, or:
cd ComfyUI/custom_nodes
git clone https://github.com/TensorKaze/ComfyUI-TkNodes
cd ComfyUI-TkNodes
pip install -r requirements.txt
Restart ComfyUI. No special dependencies for this one - it reads from ComfyUI's normal input directory, same as the stock loader.
Common issues
image dropdown only shows "none." You haven't put a file in ComfyUI's input folder, or you're looking at the wrong instance if you're running more than one ComfyUI install. Drop an image in and refresh.
Mask is blank or fully opaque. The mask comes from the alpha channel. If your source image is a plain JPEG or a flattened PNG with no transparency, there's nothing there to extract - that's expected, not a bug, and you'll need a separate mask source if you actually need one.
Resize looks softer than expected. Check upscale_method. nearest-exact and bilinear are cheap and can look rougher on a big size change; bicubic or lanczos will generally look cleaner for anything beyond a small adjustment.
Small pack, no real community trail behind it - worth knowing going in so you don't go looking for a "known issues" thread that doesn't exist. This node is a plain, useful combination of two things you'd otherwise wire separately, nothing more and nothing less.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | COMBO | The image file to load from the input directory. Select 'none' to skip loading an image. | |
| upscale_method | COMBO | The method used for scaling the image. | |
| megapixels | FLOAT | 1.000.01–16 | Target total pixels in megapixels (e.g., 1.0 for 1,048,576 pixels). |
| bypass_sttp | BOOLEAN | false | If true, skips scaling and returns the original image and mask. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | The loaded and scaled image (or original if bypassed), or None if no image is provided. |
| MASK | MASK | The mask generated from the alpha channel (scaled to match the image or original if bypassed), or None if no image is provided. |