3.8 KiB
3.8 KiB
Project Plan: ComfyUI ZIP Batch Loader Custom Node
1. Objective
Create a new, standalone Git repository for a ComfyUI custom node that implements the "Load Image Batch from Zip"
requirements. This ensures the node is modular, version-controlled, and easily installable via the ComfyUI Manager or
direct git clone.
2. Project Setup
2.1. Repository Details
- Project Name:
zip_batch_loader - Location: A directory independent of the main
charlweeds-geomancyproject workspace. For local development,https://github.com/Charlweed/ComfyUI-ZipBatchLoader.githas been created. - Primary Language: Python 3.8+ (aligning with ComfyUI's standard interpreter requirements).
2.2. Directory Structure
zip_batch_loader/
├── .gitignore
├── LICENSE # MIT License recommended for ComfyUI nodes
├── README.md # Installation instructions and examples
├── __init__.py # Node registration
├── pyproject.toml # minimal dependencies
├── requirements.txt # minimal dependencies
├── tests # unit and other tests
└── zip_batch_loader.py # Core node logic
3. Implementation Phases
Preparation:
Download a copy of the MIT LICENSE file into the project root. Create an idiomatic README.md in the project root. Create an idiomatic pyproject.toml file in the project root.
Phase 1: Core Node Logic (zip_batch_loader.py)
- Class Definition: Implement the
ZipBatchLoaderclass. INPUT_TYPES:- Query the ComfyUI
folder_paths.get_input_directory()for.zipfiles to populate a dropdown widget.
- Query the ComfyUI
RETURN_TYPES:("IMAGE", "MASK", "INT")RETURN_NAMES:("image", "mask", "count")FUNCTION:load_from_zip- Logic:
- Resolve the absolute path to the selected
.zipfile. - Open the archive using Python's built-in
zipfilemodule. - Iterate over
archive.namelist(), filtering for.png,.jpg,.jpeg. - Sort the filtered filenames alphabetically.
- Extract each image into memory, open it using
PIL.Image. - Convert each image to RGB (for the
IMAGEoutput) and L/grayscale (for theMASKoutput). - Convert the
PIL.Imageobjects to normalized PyTorch tensors. - Validate that all images have identical dimensions.
- Stack the tensors using
torch.stack()ortorch.cat()along the batch dimension. - Return the batched
IMAGEtensor,MASKtensor, and the total count.
- Resolve the absolute path to the selected
- Logic:
Phase 2: ComfyUI Registration (__init__.py)
- Import the
ZipBatchLoaderclass fromzip_batch_loader.py. - Define the node mappings required by ComfyUI:
NODE_CLASS_MAPPINGS = { "LoadImageBatchFromZip": ZipBatchLoader } NODE_DISPLAY_NAME_MAPPINGS = { "LoadImageBatchFromZip": "Load Image Batch From Zip" } __all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
Phase 3: Testing & Validation
- Unit tests: Create and tun unit tests
- Deployment: Symlink or clone the repository into a local ComfyUI instance's
custom_nodes/directory. - Basic Load: Start ComfyUI and verify the node appears in the node browser without import errors.
- Execution Test:
- Place a mock
geomancy_bundle_test.zipin the ComfyUIinputfolder. - Create a test workflow with the new node.
- Connect the node to a built-in
PreviewImageor similar debug node (using a batch selector to extract specific frames). - Verify the output order exactly matches the alphabetical sort of the internal filenames.
- Place a mock
Phase 4: Release & Documentation
- Document the installation process in
README.md. - Detail the input/output tensor shapes and the strict dimension requirement.
- Commit all changes and push to a remote git repository (e.g., GitHub) to allow seamless installation.