Prepare Image for AI JNK
Shrink images before an LLM eats your token budget
- image
- image
- width
- height
- quality
- bytes
Vision models bill by the pixel, and this node exists to stop you overpaying. "Prepare Image for AI JNK" sits in front of any multimodal API node - the README pairs it with the pack's own Ask Google Gemini - and compresses whatever you feed it down to something a token budget can afford. If you've ever sent a 4096Γ4096 render to an LLM and watched the request crawl, this is the thing that fixes that.
The name undersells the one genuinely useful behavior: it's not just a resize, it's a re-encode. The node takes your image tensor, and if its longest edge exceeds max_size (default 512), scales it down proportionally with Lanczos. Then it round-trips the image through a WebP encode/decode at your chosen webp_quality (default 80), which is where the real size savings come from. WebP at quality 80 on a flat diffusion render can be a fraction of the PNG bytes, and for an API that charges per image, per token, or per byte, that's the difference between a cheap batch run and a bill you notice. Images with alpha get flattened onto white first - the node doesn't assume the API can see through transparency.
Here's the part a lot of people miss: the bytes output isn't the pixel dimensions, it's a formatted string of the encoded file size ("34.2 KB"). So you can wire width, height, quality and bytes into a text node or a log and see exactly what you'd have sent before you actually send it. The returned image is the re-encoded, re-decoded result - same node pipeline as the API would receive, which keeps your preview honest. show_preview just toggles the temp-file preview in the UI; the node re-runs every execution (IS_CHANGED is forced to nan), so the byte count stays current even on cached runs.
Two settings matter, and they're the only ones a beginner needs to touch:
- max_size - the long edge target. 512 is a sane default for captioning and Q&A; 1024 if you actually need fine detail for the model to read it.
- webp_quality - 80 is a good balance for photos, but drop it to 50β60 for simple renders and you'll barely notice.
Install: ComfyUI Manager β search "JNK" β Install, then restart. Or:
cd ComfyUI/custom_nodes/
git clone https://github.com/Aljnk/ComfyUI-JNK-Tiny-Nodes.git
Then restart ComfyUI. The pack's requirements.txt lists opencv-python, pygame, and google-genai, but this node only needs Pillow, which ComfyUI already ships. If you installed via Manager and it pulled the extra deps, fine - they're harmless here, they're there for the Gemini and sound nodes.
Gotchas: the output image is RGB with a white background baked in, so don't use this node if you need to preserve transparency downstream. And the bytes value is informational - there's no validation gate; it will happily return a 5 MB image if you set max_size to 4096 and webp_quality to 100. If your goal is genuinely "make it small," leave the defaults alone and resist the urge to crank them.
It's a tiny utility in a grab-bag pack, but it's the one I'd keep if I had to pick. Any workflow that talks to a paid vision API should route its input through this node first - it's the difference between a token bill you ignore and one you screenshot in disbelief.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | β | |
| max_size | INT | 51264β4096 | β |
| webp_quality | INT | 801β100 | β |
| show_preview | BOOLEAN | true | β |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | β |
| width | INT | β |
| height | INT | β |
| quality | INT | β |
| bytes | STRING | β |