-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvoie.js
44 lines (36 loc) · 1.35 KB
/
envoie.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
const sharp = require('sharp');
const rewrite = require('express-urlrewrite');
function init(app) {
app.use(rewrite('/envoie/:msg1/:msg2', '/envoie?msg=:msg1&msg2=:msg2'));
app.use(rewrite('/envoie/:msg2', '/envoie?msg=ENVOIE&msg2=:msg2'));
app.get('/envoie', async (req, res) => {
let msg1 = '';
let msg2 = ''
if (req.query.msg)
msg1 = req.query.msg;
if (req.query.msg2)
msg2 = req.query.msg2;
let svgImage = `
<svg width="600" height="400">
<style>
.title { fill: #001; font-size: 45px; font-weight: bold;}
</style>
<text x="55%" y="10%" text-anchor="middle" class="title">${msg1}</text>
<text x="55%" y="25%" text-anchor="middle" class="title">${msg2}</text>
</svg>
`;
let svgBuffer = Buffer.from(svgImage);
let pngBuffer;
await sharp(svgBuffer).png().toBuffer().then((data) => {
pngBuffer = data;
}).catch((err) => {
console.log(err);
})
await sharp("envoie.png").composite([{input: pngBuffer, gravity: "center"}]).toBuffer().then(data => {
res.writeHead(200, {'Content-Type': 'image/png'});
res.end(data, 'binary');
});
}
);
}
module.exports = {init};