Skip to content

Instantly share code, notes, and snippets.

@samundrak
Last active January 25, 2021 16:55
Show Gist options
  • Save samundrak/8ef4a035b346bd3c2ca1f95610944ab8 to your computer and use it in GitHub Desktop.
Save samundrak/8ef4a035b346bd3c2ca1f95610944ab8 to your computer and use it in GitHub Desktop.
Will scan given directory and convert the image by extension.
#! /usr/bin/env node
const glob = require("glob");
const sharp = require("sharp");
glob("./data/**/*.+(jpeg|png)", (err, files) => {
Promise.allSettled(
files.map((file) => {
const link = file.split("/");
link.pop();
const newFile = `${link.join("/")}/main.jpeg`;
return sharp(file)
.jpeg({
quality: 100,
chromaSubsampling: "4:4:4",
})
.toFile(newFile);
})
)
.then(() => console.log("Written all file"))
.catch(console.error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment