JS

HOW TO CROP IMAGES IN NODEJS

RUN IN PROJECT FOLDER npm install sharp

INSTALL SHARP LIBRARY

01

LOAD SHARP & OPEN IMAGE const sharp = require("sharp"); sharp("IMG.JPG") CROP USING RESIZE TOP | BOTTOM | CENTER | RIGHT TOP | RIGHT BOTTOM | LEFT TOP | LEFT BOTTOM .resize(150, 150, { position: "left top" })

NODE CROP IMAGES

02

OR EXTRACT SPECIFIC AREA .extract({   left: 100, top: 100, width: 150, height: 150 }) SAVE TO FILE .jpeg({ quality: 30 }) toFile("CROPPED.JPG")