Verified Commit e2661d53 authored by Thibaut Broggi's avatar Thibaut Broggi
Browse files

Add params usage and fonts

    Image is still missing
    node-canvas has been update to 2.0 alpha
parent 34e87a93
......@@ -12,7 +12,7 @@
},
"license": "GPL-3.0",
"dependencies": {
"canvas": "^1.6.7",
"canvas": "2.0.0-alpha.1",
"express": "^4.16.1"
}
}
......@@ -8,22 +8,37 @@ const app = express();
const config = require('./config.json');
app.set('x-powered-by', false);
app.use(express.static('./static'));
app.get('/generate', function (req, res) {
// let bgColor = document.querySelector('.colorpicker input[type="radio"][name="bg-color"]:checked').value;
// let fgColor = document.querySelector('.colorpicker input[type="radio"][name="fg-color"]:checked').value;
// let fillText = document.getElementById('step2value').value.trim();
// let font = document.querySelector('#step3 input[type="radio"]:checked').value;
// let icon = document.querySelector('#step4 input[type="radio"]:checked').value;
// let signature = document.getElementById('signature').value.trim();
let bgColor = 'red';
let fgColor = 'yellow';
let fillText = 'shampooing';
let icon = 2;
let font = 'arial';
let signature = 'moi';
// {name: filepath}
let fonts = {
'FiraSans': 'FiraSans-Regular.otf',
'bilbo-inc': 'BilboINC.ttf',
'bluu-next': 'BluuNext-Bold.otf',
'boeticher': 'Boeticher-Roman.otf',
'combat': 'Combat.otf',
'gulax': 'Gulax.otf',
'lineal': 'Lineal.otf',
'resistance': 'Resistance.otf',
'savate': 'savate-regular.otf',
'solid-mirage': 'SolideMirageMono.otf',
'steps-mono': 'Steps-Mono.otf',
'terminal': 'terminal-grotesque_open.otf'
};
for (let i in fonts) {
Canvas.registerFont('./static/fonts/' + fonts[i], {family: i});
}
Canvas.registerFont('./static/fonts/FiraSans-Bold.otf', {family: 'FiraSans', weight: 'bold'});
app.get('/generate.png', function (req, res) {
let bgColor = req.query['bg-color'] || '#f54358';
let fgColor = req.query['fg-color'] || '#ffd201';
let fillText = req.query.text ? req.query.text.trim() : 'démocratie';
let icon = req.query.icon || 1;
let font = req.query.font || 'bluu-next';
let signature = req.query.signature ? req.query.signature.trim() : '';
let width = 600;
let height = 413;
let fontSize = 44;
......@@ -77,22 +92,22 @@ app.get('/generate', function (req, res) {
fs.readFile('./static/imgs/' + icon + '.svg', {encoding: 'utf8'}, function(err, res) {
let img = new Image();
let imgXml = res.replace(/#FFD201/g, fgColor);
img.src = 'data:image/svg+xml;base64,' + Buffer(imgXml).toString('base64');
img.onload = function() {
ctx.drawImage(img, 0, 0);
console.log('loaded');
}
img.src = 'data:image/svg+xml;base64,' + Buffer(imgXml).toString('base64');
});
let stream = canvas.pngStream();
let stream = canvas.pngStream();
stream.on('data', function(chunk) {
res.write(chunk);
});
stream.on('end', function() {
res.end();
});
};
stream.on('data', function(chunk) {
res.write(chunk);
});
})
stream.on('end', function() {
res.end();
})
});
app.get('/', function(req, res) {
res.sendfile('./static/index.html');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment