image-utility-library
Version:
A Node.js library for compressing, resizing, cropping, and applying effects to images.
16 lines (14 loc) • 485 B
JavaScript
import sharp from 'sharp';
/**
* Crop an image buffer to specific dimensions.
* @param {Buffer} imageBuffer - The image buffer.
* @param {Number} width - Width of the crop.
* @param {Number} height - Height of the crop.
* @returns {Promise<Buffer>} - Cropped image buffer.
*/
const cropImage = async (imageBuffer, width, height) => {
return await sharp(imageBuffer)
.extract({ left: 0, top: 0, width, height })
.toBuffer();
};
export default cropImage;