-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext-to-image.js
More file actions
38 lines (33 loc) · 1.43 KB
/
text-to-image.js
File metadata and controls
38 lines (33 loc) · 1.43 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
const bwipjs = require('bwip-js');
module.exports = function (RED) {
function TextToImageNode(config) {
RED.nodes.createNode(this, config);
var node = this;
node.on('input', function (msg) {
// Configuração do padrão de texto
const textPattern = msg.payload.match(/.{1,4}/g).join(" ");
// Configurações do código de barras
const opts = {
bcid: 'code128', // Código de barras a ser gerado, por exemplo, 'code128'
text: textPattern, // Texto a ser codificado
scale: 2, // Escala do código de barras
height: 40, // Altura do código de barras em pontos
includetext: true, // Incluir texto no código de barras
textxalign: 'center', // Alinhamento horizontal do texto
};
// Gera o código de barras
bwipjs.toBuffer(opts, function (err, png) {
if (err) {
node.error(err, msg);
} else {
// Converte o buffer PNG em uma imagem (base64)
msg.payload = 'data:image/png;base64,' + png.toString('base64');
// Envia a mensagem
node.send(msg);
}
});
});
}
// Registra o node
RED.nodes.registerType("text-to-image", TextToImageNode);
};