PDtools: Image Compress
Image Compress — get a PNG under X KB without losing transparency
- image
- mask
- compressed_image
- size_info
Somewhere every ComfyUI user hits it: a forum, a Discord, a marketplace upload that says "max 2 MB," and your clean 2048px PNG is 9. Saving a JPG at quality 80 works but murders the alpha channel and the crisp edges you worked for. PDtools: Image Compress is the node for that gap - it squeezes a PNG to fit a target file size (default 160 KB) by reducing the color palette, and it keeps transparency intact the whole way.
It's from the "PDtools" corner of the PDuse pack, the subsection the author (7BEII) frames as "algorithm solutions and feature re-creations." This one is a genuinely useful re-creation: a PNG-quantizer as a node.
How it works
The mechanism is what makes it interesting. It first tries the image as an optimized lossless PNG. If that's still over budget, it quantizes - reducing the image to 256, then 128, then 64, then 32 colors, re-encoding each attempt until one lands under the target. It prefers PIL's libimagequant kernel (quantize(method=3)), which handles RGBA glow and gradients without color-shifting; if your Pillow build lacks libimagequant it falls back to fastoctree (method 2), which still does full RGBA palette math. Either way, the alpha channel rides along - you don't get the classic "PNG compression turned my transparency black" disaster.
Two nice touches: a mask input that gets turned into the alpha channel (so a mask-flattened transparent result is one wire away), and per-frame reporting.
The inputs that matter
- image (
IMAGE) - frames to compress (it batches, frame by frame). - target_kb (
INT, default 160) - the size ceiling in kilobytes. 10–10240. - save_to_disk (
BOOLEAN, default on) - writes the compressed PNG into your output folder with the prefix. - filename_prefix (
STRING, defaultPD_compress) - used for the on-disk name. - mask (
MASK, optional) - becomes the alpha channel.
Outputs: compressed_image (IMAGE) and size_info (STRING) - one line per frame like [1] 1024x1024 | 151.2 KB | 带透明通道.
The trade you should know about
Re-encoding drops the embedded workflow metadata. ComfyUI stores the entire node graph in PNG text chunks (see the KB's image-io-metadata essay), and any re-encode strips them - this node is no exception. If you compress your output and then share it, nobody can drag it back into ComfyUI to recover the workflow. That's usually fine for uploads (the workflow isn't part of the deliverable), but keep a full-quality copy for yourself if you care about provenance. The size_info output, incidentally, is the perfect thing to paste into a filename or a status node so you know which frames survived compression.
Install
ComfyUI Manager: search PDuse (repo 7BEII/Comfyui_PDuse), install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse
cd Comfyui_PDuse
pip install -r requirements.txt
Restart and it appears as PDtools: Image Compress.
Gotchas
It's deterministic and lossy-by-design, so don't use it as your primary saver - it's a delivery node, not an archive node. And if libimagequant isn't in your Pillow, results on neon/glow art can look slightly banded at aggressive targets; drop the target or accept the fallback. For posting-ready PNGs under a size limit, it does the job nobody else's pack does in one node.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| target_kb | INT | 16010–10240 | — |
| save_to_disk | BOOLEAN | true | — |
| filename_prefix | STRING | PD_compress | — |
| maskopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| compressed_image | IMAGE | — |
| size_info | STRING | — |