-
Notifications
You must be signed in to change notification settings - Fork 0
/
compositor.js
93 lines (89 loc) · 1.89 KB
/
compositor.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const { fabric } = require('fabric');
const compositor = {
imagen: function (articulo, texto, referencia, titulo, nombreBot) {
var canvas = new fabric.Canvas(
null,
{
width:600,
height:1200,
backgroundColor: '#c6cae3'
}
);
var tituloTxt = new fabric.Textbox(
titulo,
{
top:6,
left:5,
width:400,
fontFamily: 'Arial',
fontWeight: 'bold',
fontSize: 16,
fill: 'white'
}
);
var rect = new fabric.Rect({
top: 0,
left: 0,
fill: 'navy',
textAlign: 'right',
width: canvas.width,
height: tituloTxt.aCoords.bl.y + 4
});
var nombreBotTxt = new fabric.Text(
nombreBot,
{
top:5,
fontFamily: 'Arial',
fontWeight: 'bold',
fontSize: 14,
fill: 'white'
}
);
nombreBotTxt.left = canvas.width - nombreBotTxt.width - 10;
if (typeof articulo !== "undefined") {
var articuloTxt = new fabric.Text(
"Artículo " + articulo,
{
top: rect.height + 10,
left: 10,
fontFamily: 'Arial',
fontSize: 16,
fontWeight: 'bold'
}
);
var articuloBLY = articuloTxt.aCoords.bl.y;
} else {
var articuloBLY = rect.height;
}
var textoTxt = new fabric.Textbox(
texto,
{
top: articuloBLY + 10,
left: 10,
width: canvas.width - 10*3,
fontFamily: 'Arial',
fontSize: 14
}
);
var referenciaTxt = new fabric.Textbox(
"-- " + referencia,
{
top:textoTxt.aCoords.bl.y + 20,
left: 20,
width: canvas.width - 20*2,
fontFamily: 'Arial',
fontSize: 14,
fontStyle: 'italic'
}
);
canvas.add(rect);
canvas.add(nombreBotTxt);
canvas.add(tituloTxt);
if (typeof articuloTxt !== "undefined") { canvas.add(articuloTxt); }
canvas.add(textoTxt);
canvas.add(referenciaTxt);
canvas.setHeight(referenciaTxt.aCoords.bl.y + 20);
return canvas;
}
};
exports.compositor = compositor;