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

Fix image drawing on server

parent e2661d53
......@@ -12,7 +12,7 @@
},
"license": "GPL-3.0",
"dependencies": {
"canvas": "2.0.0-alpha.1",
"canvas": "2.0.0-alpha.5",
"express": "^4.16.1"
}
}
......@@ -42,7 +42,7 @@ app.get('/generate.png', function (req, res) {
let width = 600;
let height = 413;
let fontSize = 44;
let canvas = new Canvas(width, height);
let canvas = Canvas.createCanvas(width, height);
let ctx = canvas.getContext('2d');
// Clear canvas
......@@ -89,17 +89,14 @@ app.get('/generate.png', function (req, res) {
ctx.fillText('La Quadrature du Net !', offset, height * 0.9);
// Draw picto
fs.readFile('./static/imgs/' + icon + '.svg', {encoding: 'utf8'}, function(err, res) {
let img = new Image();
let imgXml = res.replace(/#FFD201/g, fgColor);
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 img = new Image();
let imgXml = fs.readFileSync('./static/imgs/' + icon + '.svg');
imgXml = imgXml.toString('ascii').replace(/#FFD201/gi, fgColor);
img.src = 'data:image/svg+xml;base64,' + new Buffer(imgXml).toString('base64');
ctx.drawImage(img, 0, 0);
// Render image
let stream = canvas.pngStream();
stream.on('data', function(chunk) {
res.write(chunk);
});
......
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