Created
November 21, 2020 22:40
-
-
Save KritikaSharmaKS/b1073302961a169e9ef4674dca086a13 to your computer and use it in GitHub Desktop.
Process Images with SharpJS | Image cropping, enhance quality, reduce image size, and more...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sharp = require("sharp"); | |
sharp("Niagara-Falls-Casinos.jpg") | |
.resize({ width: 250, height: 350 }) | |
.greyscale() | |
.grayscale() | |
.negate(false) | |
.blur() | |
.toFile("output1.jpg"); | |
sharp("Niagara-Falls-Casinos.jpg") | |
.rotate(180) | |
.toFormat("png") | |
.png({ quality: 100 }) | |
.toFile("output1.png"); | |
sharp("Niagara-Falls-Casinos.jpg") | |
.flip() | |
.toFormat("png") | |
.png({ quality: 1 }) | |
.toFile("rotate-output.png"); | |
sharp("Niagara-Falls-Casinos.jpg") | |
.rotate(360) | |
.toFormat("png") | |
.png({ quality: 1 }) | |
.toFile("rotate-output.png"); | |
sharp("Niagara-Falls-Casinos.jpg") | |
.flop() | |
.toFormat("png") | |
.png({ quality: 100 }) | |
.toFile("flop.png"); | |
sharp("Niagara-Falls-Casinos.jpg") | |
.resize({ width: 500, height: 450 }) | |
.toFormat("png") | |
.png({ quality: 100 }) | |
.toFile("output.png") | |
.then(() => { | |
// This is where you can either store the image to the database | |
// or | |
// Send the image to the frontend client (React, Vue, Angular, etc) | |
console.log('Please Like Comment and Subscribe!!'); | |
}) | |
.catch((err) => console.warn(err)); // print any error on the console | |
sharp('inputGIF.gif', { animated: true }).toFile('output.webp'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment