Crop Image
Controlled node
Overview
The Crop Image node extracts a rectangular region from an input image based on specified coordinates and dimensions. It uses the Jimp image processing library to perform the crop operation, creating a new image containing only the pixels within the defined bounds.
This node is useful for:
- Removing unwanted borders or regions from images
- Focusing on specific areas of interest within an image
- Preparing images for further processing by standardizing their dimensions
- Extracting thumbnails or specific sections from larger images
Coordinate System
The crop operation uses a coordinate system where (0, 0) represents the top-left corner of the image. The x and y parameters define the starting point of the crop region, while width and height define the size of the region to extract.
Inputs
| Input | Type | Description | Default |
|---|---|---|---|
| Run | Event | Triggers the crop operation. | - |
| Image | Data | The source image to crop. Must be a valid image object (Jimp instance). | - |
| X | Number | The horizontal coordinate (in pixels) of the top-left corner of the crop region. | 0 |
| Y | Number | The vertical coordinate (in pixels) of the top-left corner of the crop region. | 0 |
| Width | Number | The width (in pixels) of the crop region. | Original image width |
| Height | Number | The height (in pixels) of the crop region. | Original image height |
Outputs
| Output | Type | Description |
|---|---|---|
| Done | Event | Fires when the image has been successfully cropped. |
| Output | Data | The resulting cropped image (Jimp instance). |
Runtime Behavior and Defaults
When the Run event fires, the node processes the input image using the following logic:
- Default Behavior: If
widthandheightare not provided, the node uses the original dimensions of the input image. Ifxandyare0(the defaults), the output will be identical to the input (a full copy of the original). - Bounds Checking: The node relies on Jimp's internal crop implementation. If the specified crop region extends beyond the image boundaries, Jimp will handle it according to its standard behavior (typically cropping to the available pixels or throwing an error depending on the Jimp version).
- Image Cloning: The node clones the input image before processing to avoid modifying the original image object in memory.
- Processing: The actual crop is performed using
img.crop(x, y, width, height).
Example Usage
Basic Crop
To crop a 100x100 pixel section starting from the top-left corner of an image:
- Connect an image source (e.g., Read Image or AI Generate Image) to the Image input.
- Set X to
0and Y to0. - Set Width to
100and Height to100. - Trigger the Run event.
- The Output will contain a 100x100 pixel image representing the top-left corner of the original.
Center Crop
To extract a 500x500 pixel region from the center of a larger image:
- Use an Image Size node to get the original dimensions (width
Wand heightH). - Calculate the center coordinates using Formula nodes:
- Center X:
(W - 500) / 2 - Center Y:
(H - 500) / 2
- Center X:
- Connect these values to the X and Y inputs of the Crop Image node.
- Set Width and Height to
500. - Trigger the crop to get a centered square extract.