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 @@ ...@@ -12,7 +12,7 @@
}, },
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"canvas": "^1.6.7", "canvas": "2.0.0-alpha.1",
"express": "^4.16.1" "express": "^4.16.1"
} }
} }
...@@ -8,22 +8,37 @@ const app = express(); ...@@ -8,22 +8,37 @@ const app = express();
const config = require('./config.json'); const config = require('./config.json');
app.set('x-powered-by', false); app.set('x-powered-by', false);
app.use(express.static('./static')); app.use(express.static('./static'));
app.get('/generate', function (req, res) { // {name: filepath}
// let bgColor = document.querySelector('.colorpicker input[type="radio"][name="bg-color"]:checked').value; let fonts = {
// let fgColor = document.querySelector('.colorpicker input[type="radio"][name="fg-color"]:checked').value; 'FiraSans': 'FiraSans-Regular.otf',
// let fillText = document.getElementById('step2value').value.trim(); 'bilbo-inc': 'BilboINC.ttf',
// let font = document.querySelector('#step3 input[type="radio"]:checked').value; 'bluu-next': 'BluuNext-Bold.otf',
// let icon = document.querySelector('#step4 input[type="radio"]:checked').value; 'boeticher': 'Boeticher-Roman.otf',
// let signature = document.getElementById('signature').value.trim(); 'combat': 'Combat.otf',
let bgColor = 'red'; 'gulax': 'Gulax.otf',
let fgColor = 'yellow'; 'lineal': 'Lineal.otf',
let fillText = 'shampooing'; 'resistance': 'Resistance.otf',
let icon = 2; 'savate': 'savate-regular.otf',
let font = 'arial'; 'solid-mirage': 'SolideMirageMono.otf',
let signature = 'moi'; '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 width = 600;
let height = 413; let height = 413;
let fontSize = 44; let fontSize = 44;
...@@ -77,10 +92,12 @@ app.get('/generate', function (req, res) { ...@@ -77,10 +92,12 @@ app.get('/generate', function (req, res) {
fs.readFile('./static/imgs/' + icon + '.svg', {encoding: 'utf8'}, function(err, res) { fs.readFile('./static/imgs/' + icon + '.svg', {encoding: 'utf8'}, function(err, res) {
let img = new Image(); let img = new Image();
let imgXml = res.replace(/#FFD201/g, fgColor); let imgXml = res.replace(/#FFD201/g, fgColor);
img.src = 'data:image/svg+xml;base64,' + Buffer(imgXml).toString('base64');
img.onload = function() { img.onload = function() {
ctx.drawImage(img, 0, 0); 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) { stream.on('data', function(chunk) {
...@@ -89,10 +106,8 @@ app.get('/generate', function (req, res) { ...@@ -89,10 +106,8 @@ app.get('/generate', function (req, res) {
stream.on('end', function() { stream.on('end', function() {
res.end(); res.end();
}); })
}; });
});
})
app.get('/', function(req, res) { app.get('/', function(req, res) {
res.sendfile('./static/index.html'); 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