ComfyUI Extension: ComfyUI Fit Mask to Image
Automatically resizes masks to match image dimensions for seamless inpainting workflows.
Custom Nodes (0)
README
ComfyUI Fit Mask to Image
Automatically resizes masks to match image dimensions for seamless inpainting workflows. Replaces a 10-node workflow chain with a single, efficient node.
Overview
This node solves a common inpainting problem: when your KSampler output dimensions (i.e. 960x960) no longer match your input (i.e. 958x958) mask dimensions due to the KSampler outputs being divisible by 8. This is also helpful for workflows where masks and images come from different sources or when upscaling changes dimensions.
Features
- One-Node Solution: Replaces 10-node workflow with single node
 - Smart Dimension Matching: Automatically scales masks to match image dimensions
 - Multiple Outputs: Fixed mask, preview image, debug mask, and masked latent
 - Inpainting Ready: Direct integration with KSampler via latent output
 - Debug Information: Detailed info output showing dimension changes
 - Nearest-Exact Scaling: Preserves mask quality during resize
 
Prerequisites
- ComfyUI installation
 - Python 3.10+ (or ComfyUI's embedded Python)
 - No additional dependencies (uses ComfyUI's PyTorch, PIL, numpy)
 
Installation
ComfyUI Registry (Recommended - Coming Soon)
The easiest way to install is through the ComfyUI Registry:
- Open ComfyUI Manager in your ComfyUI interface
 - Search for "DazzleNodes" ("Fit Mask to Image" isn't a standalone node)
 - Click Install and restart ComfyUI
 
The node will appear under: DazzleNodes → Fit Mask to Image
Alternatively, use the command line:
comfy node install fit-mask-to-image
Git Clone
cd ComfyUI/custom_nodes
git clone https://github.com/DazzleNodes/fit-mask-to-image.git
Then restart ComfyUI or use Manager → Refresh Node Definitions.
Manual Installation
- Download the latest release and extract to 
ComfyUI/custom_nodes/fit-mask-to-image/ - Restart ComfyUI
 - Find the node in: DazzleNodes → Fit Mask to Image
 
Part of DazzleNodes Collection
This node is also included in the DazzleNodes collection. If you install DazzleNodes, you automatically get this node along with other useful nodes.
Usage
Basic Workflow
- Add "Fit Mask to Image" node to your workflow (found under "DazzleNodes")
 - Connect your source IMAGE (for dimension reference)
 - Connect your MASK (to fix dimensions)
 - Optionally connect a LATENT for inpainting workflows
 
Outputs
- fixed_mask: Final mask with corrected dimensions (from alpha channel)
 - preview_image: RGB+alpha merged image for visual verification
 - info: Text showing original→target dimensions and processing status
 - masked_latent: Latent with mask applied (if latent input provided)
 
Common Use Case
Problem: You're running an inpainting workflow where:
- Your input image is 512×512
 - KSampler upscales to 1024×1024
 - Your original mask is still 512×512
 - KSampler fails with dimension mismatch
 
Solution: Insert Fit Mask to Image between upscaler and second KSampler:
- Connect upscaled IMAGE → Fit Mask to Image → 
imageinput - Connect original MASK → Fit Mask to Image → 
maskinput - Connect LATENT → Fit Mask to Image → 
latentinput (optional) - Connect 
masked_latentoutput → KSampler for inpainting 
Example Workflow
See examples/ folder for workflow JSON files demonstrating the node in action.
How It Works
- Extracts target dimensions from input image
 - Resizes mask to match using nearest-neighbor scaling (preserves mask values)
 - Converts mask to alpha channel for preview
 - Applies mask to latent if latent input provided
 - Outputs fixed mask, preview, dimensions info, and masked latent
 
Troubleshooting
Mask dimensions still don't match
Solution: Verify the image input is the target dimension source (usually the upscaled image, not the original).
Preview looks wrong
Solution: The preview is for verification only. Use the fixed_mask output for your workflow.
Latent output has wrong dimensions
Solution: Ensure the latent input matches the image dimensions (width/8 × height/8).
Development
For contributors: This project uses Git-RepoKit hooks for automatic version tracking. Run ./scripts/install-hooks.sh to set up versioning hooks.
Working on This Node
# Clone repository
git clone https://github.com/DazzleNodes/fit-mask-to-image.git
cd fit-mask-to-image
# Install hooks for version tracking
bash scripts/install-hooks.sh
# Make changes and test in ComfyUI
# Symlink to ComfyUI custom_nodes for development:
cd /path/to/ComfyUI/custom_nodes
ln -s /path/to/fit-mask-to-image fit-mask-to-image
Contributing
Contributions welcome! Please:
- Fork the repository
 - Create a feature branch
 - Test changes in ComfyUI
 - Submit a pull request
 
Like the project?
License
Fit Mask to Image, Copyright (C) 2025 Dustin Darcy
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgements
Part of the DazzleNodes collection.
