> ## Documentation Index
> Fetch the complete documentation index at: https://docs.comfy.org/llms.txt
> Use this file to discover all available pages before exploring further.

# ImageCropToMask - ComfyUI Built-in Node Documentation

> Crops an image to the bounding box of its mask, producing a centered subject over a solid background color.

Crops an image to the bounding box of its mask, producing a centered subject over a solid background color. The node composites the masked image over the chosen background and resizes the result to the specified output dimensions, making it suitable for 3D pipelines that expect a centered, background-free subject at a fixed resolution.

## Inputs

| Parameter    | Description                                                                                                                                                                                                                                                            | Data Type | Required | Range                  |
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | -------- | ---------------------- |
| `images`     | The input image or batch of images to crop.                                                                                                                                                                                                                            | IMAGE     | Yes      | —                      |
| `masks`      | The mask or batch of masks that defines the subject area. A single mask is applied to all images; otherwise the mask batch size must match the image batch size. If the mask resolution differs from the image resolution, the mask is automatically resized to match. | MASK      | Yes      | —                      |
| `width`      | Output width in pixels. (default: 1024)                                                                                                                                                                                                                                | INT       | Yes      | 64 to 4096 (step 8)    |
| `height`     | Output height in pixels. (default: 1024)                                                                                                                                                                                                                               | INT       | Yes      | 64 to 4096 (step 8)    |
| `pad_factor` | Extra margin around the mask bounding box as a multiplier. (default: 1.0)                                                                                                                                                                                              | FLOAT     | Yes      | 1.0 to 2.0 (step 0.01) |
| `grow_mask`  | Grow or shrink the mask by this many pixels before cropping. Positive values expand the mask, negative values shrink it. (default: 0)                                                                                                                                  | INT       | Yes      | -32 to 32 (step 1)     |
| `background` | Background color behind the masked subject. (default: #000000)                                                                                                                                                                                                         | COLOR     | Yes      | —                      |

Note: The crop region is centered on the mask's bounding box and its aspect ratio matches `width` / `height`. The node automatically detects and corrects an inverted mask (foreground pixels along the border, background in the center). If the mask contains no foreground pixels, the node tries the inverted mask; if that is also empty, it logs a warning and crops the entire image. An error is raised when the mask batch size does not match the image batch size and is not a single mask.

## Outputs

| Output Name | Description                                                                                                                                                  | Data Type |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------- |
| `images`    | The cropped composite images (masked subject over the chosen background color), resized to `width` x `height`. The batch size matches the input image batch. | IMAGE     |

> This documentation was AI-generated. If you find any errors or have suggestions for improvement, please feel free to contribute! [Edit on GitHub](https://github.com/Comfy-Org/embedded-docs/blob/main/comfyui_embedded_docs/docs/ImageCropToMask/en.md)

***

**Source fingerprint (SHA-256):** `fcc14b5db7318699526dd544d404f78f9d1ab362b73769276f113f2b1062b214`
