Skip to main content

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

InputTypeDescriptionDefault
RunEventTriggers the crop operation.-
ImageDataThe source image to crop. Must be a valid image object (Jimp instance).-
XNumberThe horizontal coordinate (in pixels) of the top-left corner of the crop region.0
YNumberThe vertical coordinate (in pixels) of the top-left corner of the crop region.0
WidthNumberThe width (in pixels) of the crop region.Original image width
HeightNumberThe height (in pixels) of the crop region.Original image height

Outputs

OutputTypeDescription
DoneEventFires when the image has been successfully cropped.
OutputDataThe 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 width and height are not provided, the node uses the original dimensions of the input image. If x and y are 0 (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:

  1. Connect an image source (e.g., Read Image or AI Generate Image) to the Image input.
  2. Set X to 0 and Y to 0.
  3. Set Width to 100 and Height to 100.
  4. Trigger the Run event.
  5. 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:

  1. Use an Image Size node to get the original dimensions (width W and height H).
  2. Calculate the center coordinates using Formula nodes:
    • Center X: (W - 500) / 2
    • Center Y: (H - 500) / 2
  3. Connect these values to the X and Y inputs of the Crop Image node.
  4. Set Width and Height to 500.
  5. Trigger the crop to get a centered square extract.