Overview
This node, named "Image Sharp," processes and optimizes images by converting them into one or more specified output formats. It is useful in scenarios where you need to reduce image file sizes, convert images to different formats for compatibility or performance reasons, or prepare images for web delivery with optimized settings.
Practical examples include:
- Converting uploaded images to WebP and JPEG formats to support various browsers.
- Reducing image file size while maintaining quality for faster website loading.
- Generating multiple optimized versions of an image for responsive design.
Properties
| Name | Meaning |
|---|---|
| Max File Size | Maximum allowed file size in bytes (not actively used in the provided code snippet). |
| Input Binary Field | The name of the input binary field that contains the image data to be processed. |
| Output Formats | The desired image output formats. Options: Png, Jpeg, Webp, Avif. |
Output
The node outputs an array of items, each containing optimized image data in the requested formats. For each input item, it produces one or more output items corresponding to each selected format.
Each output item includes:
json: Metadata about the processed image (such as image info returned by the optimization library).binary: The optimized image binary data under the same field name as the input binary field, with updated filename and MIME type reflecting the new format.
If multiple formats are selected, multiple output items per input item are generated, each paired back to the original input item.
Dependencies
- Uses the
sharplibrary for image processing and optimization. - Requires access to binary image data from the input.
- No external API keys or services are required.
- Relies on n8n's helper methods for handling binary data buffers and preparing binary outputs.
Troubleshooting
- Unsupported file type error: If the input binary data is not an image, the node throws an error indicating unsupported file type. Ensure the input binary field contains valid image data.
- Unsupported image format error: If an output format outside the supported list (png, jpeg, webp, avif) is specified, the node will throw an error. Use only the supported formats.
- Missing binary data: If the specified input binary field does not exist or contains no data, the node will error out. Verify the correct binary field name is set.
- File naming issues: The output filename is derived from the original but appended with
.min.and the new extension. If the original filename is missing, the output filename may be undefined or generic. - Continue on Fail: If enabled, errors for individual items do not stop execution; instead, error details are added to the output JSON for those items.
Links and References
- Sharp GitHub Repository – Documentation for the image processing library used.
- n8n Documentation - Working with Binary Data – Guide on how n8n handles binary data in nodes.