-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.js
48 lines (44 loc) · 1.29 KB
/
image.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var Jimp = require("jimp");
const path = require('path');
const fs = require('fs');
var fileName = 'Me irl___$me_irl';
var imageCaption = 'Image';
var loadedImage;
const caption= fileName.split('___$')[0]
console.log(caption)
// Jimp.read(fileName)
// .then(function (image) {
// loadedImage = image;
// return Jimp.loadFont(Jimp.FONT_SANS_16_BLACK);
// })
// .then(function (font) {
// loadedImage.print(font, 10, 10, caption)
// .write(fileName);
// })
// .catch(function (err) {
// console.error(err);
// });
const directoryPath = path.join(__dirname, 'new');
fs.readdir(directoryPath, function (err, files) {
//handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
}
//listing all files using forEach
files.forEach(function (file) {
const caption= file.split('___$')[0]
Jimp.read(directoryPath+'/'+file)
.then(function (image) {
loadedImage = image;
// console.log(image)
return Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);
})
.then(function (font) {
loadedImage.print(font, 20, 20, caption)
.write('converted/'+file);
})
.catch(function (err) {
console.error(err);
});
});
});