-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
63 lines (53 loc) · 1.84 KB
/
app.js
File metadata and controls
63 lines (53 loc) · 1.84 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
let ImageRequest = require('./models/ImageRequest')
let { writeFile } = require('fs');
let { join } = require('path');
const axios = require('axios')
let request = require('request');
let blend = require('@mapbox/blend');
let argv = require('minimist')(process.argv.slice(2));
let {
greeting = 'Hello',
who = 'You',
width = 400,
height = 500,
color = 'Pink',
size = 100,
} = argv;
let firstRequestBody = new ImageRequest(greeting, who, width, height, color, size);
let secondRequestBody = new ImageRequest(null, who, width, height, color, size);
const requestOne = axios.get(firstRequestBody.BuildRequest())
const requestTwo = axios.get(secondRequestBody.BuildRequest())
axios.all([requestOne, requestTwo]).then(axios.spread((...responses) => {
const responseOne = responses[0]
const responseTwo = responses[1]
console.log(`statusCode: ${responseOne.status}`)
//console.log(responseOne);
console.log(`statusCode: ${responseTwo.status}`)
//console.log(responseTwo);
// use/access the results
})).catch(errors => {
// react on errors.
console.error(errors);
return;
})
CombineAndSaveImage(responseOne, responseTwo);
function CombineAndSaveImage(firstRequestBody, secondRequestBody) {
let firstImage = new Buffer(firstRequestBody, 'binary');
let secondImage = new Buffer(secondRequestBody, 'binary');
blend([
{ buffer: firstImage, x: 0, y: 0 },
{ buffer: secondImage, x: secondRequestBody, width, y: 0 },
], {
width: secondRequestBody.width * 2,
height: secondRequestBody.height,
format: 'jpeg',
}, function (err, result) {
const fileOut = join(process.cwd(), `/cat-card.jpg`);
writeFile(fileOut, data, 'binary', (err) => {
if (err) {
console.log(err);
return;
}
});
});
}