A PNG converter to WebP while keeping ComfyUI embedded workflow and datetime attributes.
This repository contains a Python script to convert PNG images to WebP format. The script can also preserve the original image’s embedded metadata and datetime attributes, and optionally delete the original PNG files after conversion. If you need a converter for webui other than ComfyUI, you can check out this alternative converter: Takenoko3333/png2webp-for-a1111-and-NAI
- Convert PNG images to WebP format
- Will search in subfolders
- Configurable quality settings (0-100)
- Configurable compression method (0=fast, 6=better)
- Option to save images with lossless compression
- Preserve original ComfyUI's workflow
- Preserve original image datetime attributes
- Option to use current date instead of original datetime
- Option to delete original PNG images after conversion (send to Recycle bin)
- Detailed conversion logging to 'png2webp_conversion.log'
When converting files, the script automatically handles naming conflicts by appending a counter (e.g., image_1.webp, image_2.webp) if a file with the same name already exists.
The script automatically logs all conversion operations to 'png2webp_conversion.log', providing detailed information about each conversion process including success and any potential errors.
- Python 3.x
- Pillow
- send2trash (optional, required only for delete functionality)
-
Clone the repository:
git clone https://github.com/fernicar/png2webp_for_ComfyUI.git cd png2webp_for_ComfyUI
-
Install the required packages:
pip install Pillow send2trash
To convert PNG images to WebP format, here are some example commands:
Basic Usage (80% quality, good for most cases)
python png2webp.py --path ./images --quality 80
Faster Conversion (method 4 is slightly faster than default 6)
python png2webp.py --path ./images --quality 80 --method 4
Use current datetime instead of original
python png2webp.py --path ./images --quality 80 --use_current_date
Delete original PNG files after conversion (requires send2trash)
python png2webp.py --path ./images --quality 80 --delete_after
Lossless Conversion (slower process, almost same size as PNG)
python png2webp.py --path ./images --lossless --quality 80
--path
: Path to the directory containing PNG images (required)--quality
: WebP quality (0-100, default: 80)--method
: Compression method (0=fast, 6=better, default: 6)--lossless
: Use lossless compression (optional)--use_current_date
: Use current date instead of original file datetime (optional)--delete_after
: Send the PNG images to the recycle bin after converting to WebP (optional)
python png2webp.py --path ./images --delete_after
This command will convert all PNG images in the ./images
directory and subdirectoriesto WebP format and send the original PNG images to the recycle bin.
- For most use cases, the default quality setting of 80 provides a good balance between size and quality
- Use
--method 4
for faster conversion if speed is priority - The
--lossless
option with--quality 100
will significantly increase conversion time - Always backup important files before using the
--delete_after
option
During conversion, the script displays:
- Input and output filenames
- Applied settings and defaults
- Image dimensions
- Preserved metadata
- Conversion status
This function loads a PNG image, extracts its metadata, and saves it as a WebP image with the same filename and metadata.
This function converts a PNG image to WebP format, optionally preserving the original image's datetime attributes and sending the original PNG image to the recycle bin.
This function parses command-line arguments and processes all PNG images in the specified directory.
This project is licensed under the MIT License - see the LICENSE file for details.