Image Format Converter

Convert images between multiple formats using Sharp

Overview

This node converts images between multiple formats using the Sharp image processing library. It supports input images either as base64-encoded strings or as binary files, and outputs the converted image either as a base64 string or as a binary file. The node allows specifying output format, quality, compression effort, and lossless mode.

Common scenarios include:

  • Converting uploaded images to a standardized format for further processing.
  • Reducing image size by adjusting quality and compression settings.
  • Preparing images for web use by converting to efficient formats like WebP or AVIF.
  • Automating image format conversions in workflows that handle media assets.

Example: Convert a PNG image file input into a compressed JPEG file output with 80% quality.

Properties

Name Meaning
Input File Type Choose whether the input image is provided as Base64 string or as a binary file.
Base64 Field (Shown only if Input File Type is Base64) The JSON field name containing the base64 image data.
Output File Format Select the desired output image format. Options: AVIF, BMP, GIF, HEIF, JP2, JPG, JXL, PNG, TIFF, WEBP
Output Type Choose output as Base64 string or as a binary file.
Quality Numeric value (1-100) controlling output image quality/compression level.
Compression Effort Numeric value (0-9) controlling compression effort (higher means slower but better compression).
Lossless Mode Boolean flag to enable lossless compression where supported.

Output

The node outputs an array of items each containing either:

  • A JSON object with a data field holding the base64-encoded converted image (if output type is Base64).

  • Or a binary property named data containing:

    • fileName: the output file name with appropriate extension.
    • data: the base64-encoded image data.
    • fileType: always "image".
    • fileSize: approximate size in kilobytes.
    • fileExtension: file extension matching the output format.
    • mimeType: MIME type of the output image.

This structure enables downstream nodes to easily consume the converted image either as raw data or as a file.

Dependencies

  • Requires the Sharp library for image processing.
  • No external API keys or services are needed.
  • Runs fully within n8n environment with access to input binary or base64 data.

Troubleshooting

  • Error: "No binary data!"
    Occurs if the input type is set to file but no binary data is found on the input item. Ensure the previous node provides valid binary image data.

  • Error: "Invalid file type!"
    Happens if the binary input file is not recognized as an image. Confirm the input file is an image format supported by Sharp.

  • Error: "Unsupported: [format]"
    Raised if the selected output format is not supported by the node. Use one of the listed output formats.

  • If conversion fails but "Continue On Fail" is enabled, the error message will be returned in the output JSON under error.

  • Large images or high compression effort values may increase processing time.

Links and References

Discussion