PD_rename_image
Rename, resize, and convert a folder of images in one pass
- result
Downloaded 500 reference images that need to become img_0001.jpg … img_0500.jpg, capped at 1024px on the long edge, all in JPG. That's the job this node was built for. It's a one-folder batch tool: rename to a numbered scheme, resize keeping aspect ratio, and convert between JPG and PNG, with a single report string coming back out. If you've ever scripted this with PIL by hand, this is that script, wrapped in a ComfyUI node.
It overlaps with PD_number_star (also in this pack), but the focus here is different: that one is a general renamer with format conversion bolted on; this one is specifically "images → numbered, resized, converted." Pick by which defaults match your task.
How it works
It lists the image files in the folder (jpg/jpeg/png/bmp/tiff/webp), sorts them by name so the numbering order is deterministic, then for each one:
- Builds the new name from
rename_pattern. The defaultimg_{index:04d}givesimg_0001,img_0002, …;{index}is the 1-based position, and{original}is the original stem if you want it preserved. - Converts to
output_format- JPG flattens alpha onto a white background, PNG converts palette/LA modes to RGBA. - Resizes the long edge down to
max_size(LANCZOS), only if the image is actually larger. - Saves the result and deletes the original file if the name changed.
So it's not just a rename - it's a re-encode-and-replace. Alpha loss in JPG is the main data casualty to be aware of.
The inputs that matter
input_path- the folder. Must exist and be a directory, or you get an error string back.rename_pattern-img_{index:04d}style; supports{index}with zero-padding via format spec and{original}.max_size(128–4096, default 1024) - longest-edge cap.output_format-JPGorPNG.
Output: result - a text report with path, size cap, format, and per-file success/failure counts.
Installing it
Part of Comfyui_PDuse by 7BEII. ComfyUI Manager (search "PDuse") or:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse.git
cd Comfyui_PDuse
pip install -r requirements.txt
Restart ComfyUI. No models; pack deps are numpy, Pillow, scipy, opencv-python, torchvision. Docs are Chinese-first.
Where people get burned
Originals are deleted. When the new filename differs from the old one, the source file is removed - there's no keep-both option, and unlike PD_RenameV2 (same pack), there's no copy-to-a-new-folder escape hatch here. Work on a copy. Second, the numbering order comes from os.listdir + sort, which is fine for img_0001.jpg style names but will renumber everything if you rerun it on a folder that's already been renamed - rerunning is not idempotent. Third, JPG conversion destroys transparency; if your set has PNGs with alpha, don't pick JPG unless you're okay with white backgrounds baked in.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| input_path | STRING | — | |
| max_size | INT | 1024128–4096 | — |
| output_format | COMBO | JPG | 2 options: JPG, PNG |
| rename_pattern | STRING | img_{index:04d} | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | STRING | — |