commit initial
This commit is contained in:
25
src/index.ts
Normal file
25
src/index.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import Jimp from 'jimp';
|
||||
import fs from 'fs';
|
||||
|
||||
const invertColors = async (folder: string) => {
|
||||
try {
|
||||
|
||||
const files = fs.readdirSync(folder);
|
||||
// Filtre cool
|
||||
const imageFiles = files.filter(file => file.match(/\.(jfif)$/));
|
||||
for (const file of imageFiles) {
|
||||
// read image
|
||||
const image = await Jimp.read(`${folder}/${file}`);
|
||||
image.invert();
|
||||
// change name
|
||||
const newFileName = '.' + file;
|
||||
// save image with new file name
|
||||
await image.writeAsync(`${folder}/${newFileName}`);
|
||||
console.log("Images have been inverted and rename " + '${newFileName}')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
invertColors('./images');
|
Reference in New Issue
Block a user