Overview
The Edit Image+ node's "Crop" operation allows you to crop an image found in a specified binary property. This is useful for extracting a specific region from an image, such as focusing on a face, product, or area of interest. Typical use cases include preparing images for thumbnails, removing unwanted borders, or standardizing image sizes for further processing.
Practical examples:
- Automatically cropping user-uploaded profile pictures to a square format.
- Extracting a section of a scanned document for OCR.
- Cropping product images to focus on the item for e-commerce listings.
Properties
Below are the input properties relevant to the "Crop" operation:
Display Name | Type | Description |
---|---|---|
Property Name | String | Name of the binary property in which the image data can be found. |
Width | Number | Crop width (in pixels). |
Height | Number | Crop height (in pixels). |
Position X | Number | X (horizontal) position to crop from (in pixels). |
Position Y | Number | Y (vertical) position to crop from (in pixels). |
Options | Collection | Additional options (see below). |
Options (Collection):
- File Name (String): File name to set in binary data.
- Format (Options: bmp, gif, jpeg, png, tiff, webp): Set the output image format.
- Quality (Number, 0–100): Sets the compression level for jpeg/png/tiff formats (higher is better quality).
Output
- The node outputs the processed image in the specified binary property (as defined by "Property Name").
- The output is a binary object containing:
data
: The cropped image data (buffer).mimeType
: MIME type of the resulting image (e.g.,image/jpeg
).fileExtension
: File extension based on the selected format (e.g.,jpeg
,png
).fileName
: (Optional) Custom file name if provided.
- The original JSON data from the input item is preserved and passed through.
Example output structure:
{
"json": { /* original input data */ },
"binary": {
"data": {
"data": "<cropped image buffer>",
"mimeType": "image/png",
"fileExtension": "png",
"fileName": "custom_name.png"
}
}
}
Dependencies
- No external API keys required.
- Relies on the following npm packages (bundled with the node):
gm
(GraphicsMagick/ImageMagick wrapper)tmp-promise
fs
,path
,util
- No special n8n configuration or environment variables are needed for the crop operation.
Troubleshooting
Common issues:
Missing Binary Data:
Error message:No binary data property "data" exists on item!
Resolution: Ensure that the input item contains the specified binary property with valid image data.Invalid Crop Parameters:
Error message: May fail silently or throw errors if crop dimensions exceed the image bounds.
Resolution: Make sure "Width", "Height", "Position X", and "Position Y" are within the actual image size.Unsupported Format:
Error message: Errors related to unsupported output formats.
Resolution: Choose a supported format (bmp, gif, jpeg, png, tiff, webp).Quality Option Not Applied:
Note: The "Quality" option only affects jpeg, png, and tiff formats.