# 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