Skip to content

Instantly share code, notes, and snippets.

@indreklasn
Last active October 25, 2020 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indreklasn/a5567ab69957128dd5e50e5ef917958c to your computer and use it in GitHub Desktop.
Save indreklasn/a5567ab69957128dd5e50e5ef917958c to your computer and use it in GitHub Desktop.
const sharp = require("sharp");
sharp("example-image.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)
})
.catch((err) => console.warn(err)); // send a warning to the console if there are any errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment