-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (51 loc) 路 1.27 KB
/
index.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
const url = require('url');
const fs = require('fs');
const fabric = require('fabric').fabric;
var request = require('request').defaults({encoding: null});
module.exports = (req, res) => {
const {pathname, query} = url.parse(req.url, true);
if (!query.title || !query.author) return '';
const canvas = fabric.createCanvasForNode(1200, 630);
const container = new fabric.Rect({
width: 1200,
height: 500,
fill: '#f9fafc',
});
const title = new fabric.Textbox(query.title, {
fontFamily: 'Interface',
fontSize: 54,
fontWeight: 500,
lineHeight: 1,
fill: '#121212',
width: 1000,
left: 100,
});
const author = new fabric.Textbox(query.author, {
fontFamily: 'Interface',
fontSize: 34,
fontWeight: 500,
lineHeight: 1,
fill: '#121212',
width: 1000,
left: 100,
});
const textGroup = new fabric.Group([title, author], {
height: 500,
});
author.set({
top: title.getHeight() / 2 + 10,
});
var mainGroup = new fabric.Group([container]);
const footer = new fabric.Rect({
width: 1202,
height: 140,
top: 630 - 140,
left: -1,
fill: '#4141FF',
});
canvas.add(mainGroup);
canvas.add(textGroup);
canvas.add(footer);
canvas.createPNGStream().pipe(res);
};