File size: 3,016 Bytes
bfbe8cd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | # MASK CROP MASTER β ComfyUI Custom Node
**Always-square mask crop, even at image edges.**
## The Problem
When you mask a region at the **edge** of an image, the standard `Mask Crop Region` node from was-ns produces a **rectangular** crop instead of a square. This happens because it clamps the crop dimensions when the square extends beyond the image bounds.
## The Solution
`MASK CROP MASTER` **repositions** the square instead of clamping it. When the crop would extend past an image edge, it slides the square inward so it always fits completely inside the image.
```
was-ns (rectangle): MASK CROP MASTER (square):
ββββββββββββββββββββββ ββββββββββββββββββββββ
ββββββββββββββββββββββ ββββββββββββββββββββββ
ββββββββββββββββββββββ ββββββββββββββββββββββ
ββββββββββββββββββββββ ββββββββββββββββββββββ
ββββββββββββββββββββββ ββββββββββββββββββββββ
ββββββββββββββββββββββ ββββββββββββββββββββββ
400Γ200 (broken) 400Γ400 (correct)
```
## Installation
```bash
cd ComfyUI/custom_nodes
git clone https://huggingface.co/YOUR_USERNAME/MaskCropMaster.git
```
Restart ComfyUI after cloning.
## Usage
Drop-in replacement for `Mask Crop Region` from was-ns:
1. **Remove** the old `Mask Crop Region` node from your workflow
2. **Add** `MASK CROP MASTER` from the `WAS Suite/Image/Masking` category
3. **Connect** the same inputs: `mask`, `padding`, `region_type`
4. **Connect** the same outputs: `cropped_mask`, `crop_data`, coordinates, dimensions
## Inputs
| Input | Type | Default | Description |
|-------|------|---------|-------------|
| `mask` | MASK | β | Input mask |
| `padding` | INT | 24 | Padding around the bounding box before squaring |
| `region_type` | COMBO | "dominant" | "dominant" or "minority" (was-ns compatible) |
## Outputs
| Output | Type | Description |
|--------|------|-------------|
| `cropped_mask` | MASK | Square-cropped mask |
| `crop_data` | CROP_DATA | Compatible with `Mask Paste Region` |
| `top_int` | INT | Y position of the square |
| `left_int` | INT | X position of the square |
| `right_int` | INT | Bottom edge |
| `bottom_int` | INT | Right edge |
| `width_int` | INT | Width (= side length) |
| `height_int` | INT | Height (= side length) |
## Compatibility
- Works with `Mask Paste Region` from was-ns (same `crop_data` format)
- Same output names β minimal rewiring needed
- Tested with ComfyUI latest version
## License
Apache 2.0
|