Skip to content

Instantly share code, notes, and snippets.

@KritikaSharmaKS
Created November 21, 2020 22:40
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KritikaSharmaKS/b1073302961a169e9ef4674dca086a13 to your computer and use it in GitHub Desktop.
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...
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