I want to identify a directory, 'inbox_screenshots', which contains a list of up to 100 png files from 1-100. I want to loop through each image and write its filename onto the actual image (i.e 1.png written onto 1.png etc)
I have tried
for (i = 1; i < 100; i++) {
let fname = path + i + ".png"
fs.access(fname, (err) => {
if (err) {
console.log("The file does not exist.");
} else {
console.log("The file exists.");
Jimp.read(fname)
.then(function (image) {
loadedImage = image;
return Jimp.loadFont(Jimp.FONT_SANS_128_BLACK);
})
.then(function (font) {
loadedImage.print(font, 900, 100, i)
.write(fname);
})
.catch(function (err) {
console.error(err);
});
}
});
}
After running this all the images have 100 typed onto them, rather than 1,2,3,4,5etc (filenames are 1.png->100.png)
I also tried
fs.readdirSync(path).forEach(file => {
console.log(file);
Jimp.read(path + file)
.then(function (image) {
loadedImage = image;
return Jimp.loadFont(Jimp.FONT_SANS_128_BLACK);
})
.then(function (font) {
loadedImage.print(font, 900, 100, file)
.write(path + file);
})
.catch(function (err) {
console.error(err);
});
});
This works for writing the filenames onto the images but it writes ALL the filenames onto each image, overlapping, so there will be 1,2,3,4,5,6,7,8,9 etc all on each image, overlapped.
Would appreciate a point in the right direction.
EDIT i was missing a let in the first example
Now when i add the let it puts the filename on the image but it keeps stacking the last filename onto it, for example the 6th iteration will have 1,2,3,4,5,6 on it, rather than just 6. Here's an example: https://i.gyazo.com/1c29db37dc564c75f78a696ca46cfc80.png (i can't add images yet)