ComfyUI Node

Shrink Image

Shrink images to fit a box — without ever upscaling

By dzqdzq·Created 2 years ago·Updated 2 years ago· 4
Shrink Image
  • image
  • IMAGE
modescale
resize_algorithmLANCZOS
scale0.50
width100
height100

ShrinkImage does one thing: makes an image (or a whole batch) smaller, either by a fixed scale factor or to fit inside a target box. It ships in the same pack as FastAlphaCropper - the pack's whole framing is "stop your images from getting too large" - and it's the resize half of that bargain.

When would you reach for it? The honest answer: it's a light utility, and ComfyUI already ships ImageScale, so you need a specific reason. The specific reasons here are (1) the fit-to-box mode that never upscales, (2) alpha retention - feed it an RGBA cutout and it stays RGBA on the way out, and (3) batch handling. If you've just cropped a transparent subject down and want a small version for a preview, an upload, or to keep a VRAM-hungry step cheap, it does the job with one node.

How it works

The source is about as simple as it gets: it converts each frame to a PIL image, calls resize with your chosen algorithm, and stacks the results back into a batch. The interesting part is the mode input:

  • scale - multiplies the original dimensions by the scale float (default 0.5, max 1.0). Straightforward factor-based shrink.
  • pixels - fits the image inside width × height while preserving aspect ratio. It computes the scale as min(target/current) per axis, then clamps at the original size - so it will happily shrink a 2000×1000 image to 100×50, but it will never blow something up past its original dimensions. Give it a box bigger than the image and it just leaves it alone.

The default resize algorithm is LANCZOS, which is the right default for downscaling - it's what you want for quality. The other options (NEAREST, BILINEAR, BICUBIC) are there if you need pixel-art-style output or speed.

Inputs worth setting

  • mode - scale or pixels. Decide which behavior you want first; the other inputs only apply to one of them.
  • scale (FLOAT, default 0.5) - only used in scale mode. 0.5 halves each dimension (quarter the pixels).
  • width / height (FLOAT, default 100, max 10000) - only used in pixels mode. These are caps, not exact targets: the aspect ratio wins, and one side will usually come in under its target.

Output is a single IMAGE, sized for whatever comes next.

Gotchas from the actual code

  • It prints img.shape= to your console for every frame in the batch. Harmless debug noise, but it will clutter your log on long batches - just ignore it.
  • width/height are typed as FLOAT in the schema even though they're conceptually dimensions. Don't fight it; values like 100.0 work fine.
  • Like its sibling node, it expects the alpha channel to be there if your input has one - it doesn't strip or add transparency, it just resizes whatever it's given.
  • It's a shrink-only tool by design. If you need to upscale, that's a whole different job (see the upscaling knowledge base); this node won't pretend otherwise.

Install

Same story as the whole pack - no dependencies beyond torch/PIL/torchvision (already in ComfyUI), no model files. In ComfyUI Manager, search "ComfyUI-crop-alpha", or:

cd ComfyUI/custom_nodes
git clone https://github.com/dzqdzq/ComfyUI-crop-alpha

Restart, and it shows up in image/processing.

Verdict

It's a small node that does a small job well, and the fit-without-upscaling behavior is genuinely useful if you're feeding variable-size images into a fixed-size step. That said, be honest about when you need it - for most resizing chores ComfyUI's built-in nodes are fine, and the niche here is the alpha-safe, never-upscale fit. For that niche, it works, it's free of dependencies, and it costs you nothing to have around.

Categoryimage/processing

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
modeCOMBOscale2 options: scale, pixels
resize_algorithmCOMBOLANCZOS4 options: NEAREST, BILINEAR, BICUBIC, LANCZOS
scaleoptFLOAT0.500.01–1
widthoptFLOAT1002–10000
heightoptFLOAT1002–10000

Outputs (1)

NameTypeDescription
IMAGEIMAGE