Commit 856711d6 authored by Luc Didry's avatar Luc Didry
Browse files

Fix #4

parent 6b407180
Pipeline #23903 passed with stage
in 23 seconds
{
"name": "Timeline",
"version": "1.0.1",
"description": "Responsive timeline",
"repository": "https://github.com/brunodsgn/responsive-timeline",
"name": "WemaWema",
"version": "0.0.1",
"description": "We make meme generator",
"repository": "https://framagit.org/luc/wemawema",
"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"
},
"author": "Luc Didry",
"license": "AGPLv3",
"dependencies": {
"canvas": "^1.6.7"
"body-parser": "^1.18.2",
"request-form": "^1.0.2"
}
}
const http = require('http');
const http = require('http');
const parse = require('request-form');
var url = require('url');
var Canvas = require('canvas')
......@@ -21,48 +22,56 @@ const requestHandler = (request, response) => {
var py = (queryData.py !== undefined) ? queryData.py : '350';
var ps = (queryData.ps !== undefined) ? queryData.ps : '220';
if (queryData.text !== undefined) {
p = queryData.text;
}
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;
while (ctx.measureText(w).width > 725) {
ctx.font = 'bold '+(parseInt(ws) - i++)+'px sans-serif';
}
ctx.fillText(w, parseInt(wx), parseInt(wy));
parse(request, {})
.then(data => {
console.log(data);
if (data.text !== undefined) {
response.writeHead(200, {
'Content-Type': 'application/json'
});
response.end(JSON.stringify({response_type: 'in_channel', text: fullUrl(request)+'?p='+encodeURIComponent(data.text)}));
} else {
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;
while (ctx.measureText(w).width > 725) {
ctx.font = 'bold '+(parseInt(ws) - i++)+'px sans-serif';
}
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)';
// Write new value
ctx.font = 'bold '+parseInt(ps)+'px sans-serif';
ctx.fillStyle = 'rgba(0, 0, 0, 1)';
i = 0;
while (ctx.measureText(p).width > 725) {
ctx.font = 'bold '+(parseInt(ps) - i++)+'px sans-serif';
}
ctx.fillText(p, parseInt(px), parseInt(py));
i = 0;
while (ctx.measureText(p).width > 725) {
ctx.font = 'bold '+(parseInt(ps) - i++)+'px sans-serif';
}
ctx.fillText(p, parseInt(px), parseInt(py));
var data = canvas.toDataURL().replace('data:image/png;base64,','');
var data = canvas.toDataURL().replace('data:image/png;base64,','');
var img = new Buffer(data, 'base64');
var img = new Buffer(data, 'base64');
response.writeHead(200, {
'Content-Type': 'image/png',
'Content-Length': img.length
response.writeHead(200, {
'Content-Type': 'image/png',
'Content-Length': img.length
});
response.end(img);
}
}, err => {
});
response.end(img);
}
const server = http.createServer(requestHandler)
......@@ -129,3 +138,8 @@ function roundRect(ctx, x, y, width, height, radius, fill, stroke) {
}
}
function fullUrl(req) {
return req.headers['x-forwarded-proto']+'://'+req.headers['host']+'/WeMake.png';
}
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