-
Notifications
You must be signed in to change notification settings - Fork 1
/
storymaker.js
47 lines (45 loc) · 1.4 KB
/
storymaker.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
import download from 'image-downloader'
import jimp from 'jimp'
import database from './database/sentence.json';
import fs from 'fs';
export function storyMaker(answer){
return new Promise((resolve, reject) => {
// TODO: Log the answer in a database
//sentence = answer
console.log(`Wait until process done`)
let font = jimp.FONT_SANS_64_WHITE
const timestamp = Date.now()
//download random natural photo
const options = {
url : 'https://picsum.photos/540/960/?random',
dest : 'download/photo.jpg'
}
download.image(options)
.then((file, image) => {
jimp.read(file.filename)
.then((photo) => {
jimp.loadFont(font).then((font) => {
photo.brightness(-0.5)
.blur(1)
.print(font, 20, 20, answer,1)
.write(`edited/photo-${timestamp}.jpg`)
database.sentences.push({"username": "", "answer": answer});
fs.writeFile("database/sentence.json", JSON.stringify(database), function(){
resolve({
status : 1,
data : {
timestamp : timestamp
}
})
})
})
})
.catch((err) => {
reject(err)
})
})
.catch((err) => {
reject(err)
})
});
}