Skip to content

Instantly share code, notes, and snippets.

@dusskapark
Created August 13, 2021 16:11
Show Gist options
  • Save dusskapark/084a2b91bbf8e9782afa7cc4cc2232b6 to your computer and use it in GitHub Desktop.
Save dusskapark/084a2b91bbf8e9782afa7cc4cc2232b6 to your computer and use it in GitHub Desktop.
const fs = require("fs");
const path = require("path");
const sharp = require("sharp");
const imageFolder = "./images/origin/img/";
const outputFolder = "./images/resize/img/";
fs.readdir(imageFolder, (err, files) => {
// On error, show it and return
err ? console.log("forEach: ", err) : true;
files.forEach((file) => {
sharp(imageFolder + file)
.resize({ height: 640 })
.toFile(outputFolder + file)
.then((info) => {
console.log(info);
})
.catch((err) => {
// output.jpg is a 640 height
console.log(err);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment