Last active
January 25, 2021 16:55
-
-
Save samundrak/8ef4a035b346bd3c2ca1f95610944ab8 to your computer and use it in GitHub Desktop.
Will scan given directory and convert the image by extension.
This file contains 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
#! /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