[SSN] Prep Trim Scale
Auto-trim transparent edges, then scale to fit — the sprite-prep workhorse
- images
- IMAGE
[SSN] Prep Trim Scale is the most clever node in the prep family. It takes an image, auto-trims the transparent borders, scales it to fit inside a target canvas while keeping the aspect ratio, and centers it. The whole "make this cutout sit cleanly in a frame" job in one node - and it's the one I'd actually reach for out of this pack.
Here's the problem it solves. When a background-removal model or a sprite-render pipeline hands you an image, there's usually a lot of empty transparent margin around the actual subject - the matte is bigger than the content. That margin makes the subject look small and randomly placed when you composite or encode. Trim Scale fixes it in two steps: first it trims the transparent borders tight against the subject (using trim_threshold, the alpha value that counts as "content" - default 0 means any alpha above zero is kept, and trim_padding adds a border back around the subject so it doesn't get shaved too tight); then it scales the trimmed result to fit target_width × target_height while preserving aspect ratio, and centers it on the canvas.
The inputs are images, trim_padding, trim_threshold (0–255), target_width, target_height, and debug. The debug toggle is the fun one and it's actually real - turn it on and the node fills the background with random colors (red on the trim stage, random per frame on the scale stage) so you can see exactly where the trim boundaries and centering are. That's a genuinely useful debugging aid: run once in debug, eyeball the framing, then flip it off for the real output.
Mechanically it's OpenCV doing the heavy lifting - cv2.resize with INTER_AREA (good downsampling) after the trim. Scaling keeps aspect ratio and fits inside the canvas, so a wide subject in a tall canvas gets letterboxed with transparent bars, which you then decide the fate of (flatten, or composite over a background). Like the other prep nodes it requires RGBA input and asserts it loudly.
Where it fits: the classic chain is background-removal or Draw Text → Trim Scale → Flatten Alpha → output. Trim the excess, size it to the frame, then pick a background. It's the difference between "subject floating in a huge empty box" and "subject sitting properly in frame."
Install
Part of smn_support_nodes by SummonTheCat. ComfyUI Manager → search smn_support_nodes → Install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/SummonTheCat/smn_support_nodes
Restart required. Dependencies are opencv-python (this node's engine) and imageio-ffmpeg, both auto-installed; no models.
Troubleshooting
Three things to know. (1) It requires RGBA - a 3-channel image throws immediately. (2) trim_threshold is the "what counts as background" knob: if your matte has soft, semi-transparent edges and the trim keeps biting into them, raise the threshold above 0 so only truly-transparent pixels get trimmed away. (3) It scales to fit, not to fill - a subject with a mismatched aspect ratio leaves transparent bars, not a cropped canvas. That's usually what you want; if you wanted a hard center-crop to the exact target instead, SsnPrepCrop is the simpler sibling.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| trim_padding | INT | — | |
| trim_threshold | INT | 0–255 | — |
| target_width | INT | — | |
| target_height | INT | — | |
| debug | BOOLEAN | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |