Commit 52180304 authored by Luc Didry's avatar Luc Didry
Browse files

PoC d'un serveur WemaWema

parent 41cdff4e
Pipeline #23874 passed with stage
in 18 seconds
service/
*.swp
*/node_modules
......@@ -193,4 +193,3 @@ function roundRect(ctx, x, y, width, height, radius, fill, stroke) {
}
}
{
"name": "Timeline",
"version": "1.0.1",
"description": "Responsive timeline",
"repository": "https://github.com/brunodsgn/responsive-timeline",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Bruno Rodrigues",
"license": "MIT",
"devDependencies": {
"compass": "^0.1.0",
"del": "^0.1.3",
"gulp": "^3.8.10",
"gulp-imagemin": "^2.0.0",
"gulp-ruby-sass": "^0.7.1"
},
"dependencies": {
"canvas": "^1.6.7"
}
}
const http = require('http');
const port = 3000;
var url = require('url');
var Canvas = require('canvas')
const requestHandler = (request, response) => {
var queryData = url.parse(request.url, true).query;
var Image = Canvas.Image;
var canvas = new Canvas(800, 400);
var ctx = canvas.getContext('2d');
var w = (queryData.w !== undefined) ? queryData.w : 'WE MAKE';
var wx = (queryData.wx !== undefined) ? queryData.wx : '400';
var wy = (queryData.wy !== undefined) ? queryData.wy : '160';
var ws = (queryData.ws !== undefined) ? queryData.ws : '150';
var p = (queryData.p !== undefined) ? queryData.p : 'PORN';
var px = (queryData.px !== undefined) ? queryData.px : '400';
var py = (queryData.py !== undefined) ? queryData.py : '350';
var ps = (queryData.ps !== undefined) ? queryData.ps : '220';
ctx.fillStyle = 'rgba(252, 210, 5, 1)';
roundRect(ctx, 0, 0, 800, 400, 20, true, false);
// rounded rectangle
ctx.lineWidth = 20;
ctx.strokeStyle = 'rgb(0, 0, 0)';
roundRect(ctx, 25, 25, 750, 350, 20, false);
ctx.textAlign="center";
// Write WE MAKE
ctx.font = 'bold '+parseInt(ws)+'px sans-serif';
ctx.fillStyle = 'rgba(0, 0, 0, 1)';
var i = 0;
console.log('w: '+ctx.measureText(w).width);
while (ctx.measureText(w).width > 725) {
ctx.font = 'bold '+(parseInt(ws) - i++)+'px sans-serif';
}
console.log('w: '+ctx.measureText(w).width);
ctx.fillText(w, parseInt(wx), parseInt(wy));
// Write new value
ctx.font = 'bold '+parseInt(ps)+'px sans-serif';
ctx.fillStyle = 'rgba(0, 0, 0, 1)';
i = 0;
console.log('p: '+ctx.measureText(p).width);
while (ctx.measureText(p).width > 725) {
ctx.font = 'bold '+(parseInt(ps) - i++)+'px sans-serif';
}
console.log('p: '+ctx.measureText(p).width);
ctx.fillText(p, parseInt(px), parseInt(py));
var data = canvas.toDataURL().replace('data:image/png;base64,','');
var img = new Buffer(data, 'base64');
response.writeHead(200, {
'Content-Type': 'image/png',
'Content-Length': img.length
});
response.end(img);
}
const server = http.createServer(requestHandler)
server.listen(port, (err) => {
if (err) {
return console.log('something bad happened', err)
}
console.log(`server is listening on ${port}`)
});
function roundRect(ctx, x, y, width, height, radius, fill, stroke) {
if (typeof stroke == 'undefined') {
stroke = true;
}
if (typeof radius === 'undefined') {
radius = 5;
}
if (typeof radius === 'number') {
radius = {tl: radius, tr: radius, br: radius, bl: radius};
} else {
var defaultRadius = {tl: 0, tr: 0, br: 0, bl: 0};
for (var side in defaultRadius) {
radius[side] = radius[side] || defaultRadius[side];
}
}
ctx.beginPath();
ctx.moveTo(x + radius.tl, y);
ctx.lineTo(x + width - radius.tr, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius.tr);
ctx.lineTo(x + width, y + height - radius.br);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius.br, y + height);
ctx.lineTo(x + radius.bl, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius.bl);
ctx.lineTo(x, y + radius.tl);
ctx.quadraticCurveTo(x, y, x + radius.tl, y);
ctx.closePath();
if (fill) {
ctx.fill();
}
if (stroke) {
ctx.stroke();
}
}
[Unit]
Description=WE MAKE meme generator
Documentation=https://framagit.org/luc/wemawema
Requires=network.target
After=network.target
[Service]
User=www-data
WorkingDirectory=/var/www/wemawema/server/
ExecStart=/usr/bin/node wemawema.js
[Install]
WantedBy=multi-user.target
Supports Markdown
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