Function convertImage

  • Converts an image from one format to another using Sharp

    Parameters

    • input: string | Buffer

      Path to the source image or image buffer

    • format: ImageFormat

      Target format to convert to

    • options: ConversionOptions = {}

      Additional conversion options

    Returns Promise<Buffer>

    Converted image as buffer

    Example

    const { convertImage, ImageFormat } = require("kiutils");

    // Convert from file path
    convertImage("image.png", ImageFormat.WEBP)
    .then(buffer => fs.writeFileSync("image.webp", buffer));

    // Convert from buffer with options
    const inputBuffer = fs.readFileSync("image.jpg");
    convertImage(inputBuffer, ImageFormat.PNG, { width: 800 })
    .then(buffer => fs.writeFileSync("resized.png", buffer));

Generated using TypeDoc