A lightweight Node.js utility for compressing images using the Sharp library.
You can install the utility via npm:
npm install image-compression-utility
const compressImage = require('image-compression-utility');
// Example usage
const inputPath = 'input.jpg';
const outputPath = 'output.jpg';
const options = {
quality: 80,
maxWidth: 1024,
maxHeight: 768
};
// Compress the image
compressImage(inputPath, outputPath, options);
Compresses an image using the Sharp library.
-
inputPath
: The file path of the original image. -
outputPath
: The file path where the compressed image will be saved. -
options
(optional): An object containing compression options. Available options are:-
quality
: The quality of the compressed image (default:80
). -
maxWidth
: The maximum width of the compressed image (default:1024
). -
maxHeight
: The maximum height of the compressed image (default:768
).
-
This project is licensed under the MIT License - see the LICENSE file for details.