DEV Community

Cover image for Crop images seamlessly in Node.js
Kunal Kande Patil
Kunal Kande Patil

Posted on • Updated on

Crop images seamlessly in Node.js

Cropify helps to crop and round image corners seamlessly.

Installation

npm install cropify
Enter fullscreen mode Exit fullscreen mode

Usage

const { cropImage } = require("cropify");
const fs = require("fs")

const imagePath = 'https://th.bing.com/th/id/OIGP.914kwCtAqWQ7Lkx5hT2B?pid=ImgGn';

const cropX = 0;
const cropY = 0;
const cropWidth = 1280;
const cropHeight = 720;
const borderRadius = 80;

cropImage({
    imagePath: imagePath,
    x: cropX,
    y: cropY,
    width: cropWidth,
    height: cropHeight,
    borderRadius: borderRadius,
    cropCenter: true
}).then(x => {
    fs.writeFileSync("cropped-image.png", x);
});
Enter fullscreen mode Exit fullscreen mode

Output

Example of Cropify

Top comments (0)