Added /pride
This commit is contained in:
parent
b262c002af
commit
a3ab0e3ef7
5 changed files with 64 additions and 6 deletions
|
@ -436,6 +436,23 @@
|
||||||
"size": 1200
|
"size": 1200
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"pride": {
|
||||||
|
"src": "./resources/PrideOverlay.png",
|
||||||
|
"z": 2,
|
||||||
|
"anchor": {
|
||||||
|
"x": {
|
||||||
|
"position": 0,
|
||||||
|
"offset": 0,
|
||||||
|
"size": 512
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"position": 0,
|
||||||
|
"offset": 0,
|
||||||
|
"size": 512
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"filter": "pride"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
31
filters.js
Normal file
31
filters.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
const _ = require('lodash');
|
||||||
|
const Canvas = require('canvas');
|
||||||
|
const { _drawImage } = require('./imageex');
|
||||||
|
|
||||||
|
const { createCanvas, Image } = Canvas;
|
||||||
|
|
||||||
|
const filters = {
|
||||||
|
pride: (canvas, source, x, y, props) => {
|
||||||
|
_.each(canvas.frames, frame => {
|
||||||
|
const tmpCanvas = createCanvas(frame.canvas.width, frame.canvas.height);
|
||||||
|
const tmpCtx = tmpCanvas.getContext('2d');
|
||||||
|
_drawImage(tmpCtx, frame.canvas, x, y, props);
|
||||||
|
const multiplyProps = _.extend({}, props, { attributes: { globalCompositeOperation: 'multiply' } });
|
||||||
|
_drawImage(tmpCtx, source.frames[0].canvas, x, y, multiplyProps);
|
||||||
|
|
||||||
|
|
||||||
|
const tmpCanvas2 = createCanvas(frame.canvas.width, frame.canvas.height);
|
||||||
|
const tmpCtx2 = tmpCanvas2.getContext('2d');
|
||||||
|
_drawImage(tmpCtx2, frame.canvas, x, y, props);
|
||||||
|
const sourceInProps = _.extend({}, props, { attributes: { globalCompositeOperation: 'source-in' } });
|
||||||
|
_drawImage(tmpCtx2, source.frames[0].canvas, x, y, sourceInProps);
|
||||||
|
|
||||||
|
const combineProps2 = _.extend({}, props, { attributes: { globalCompositeOperation: 'source-atop', globalAlpha: 0.9 } });
|
||||||
|
_drawImage(frame.ctx, tmpCanvas2, x, y, combineProps2);
|
||||||
|
const combineProps = _.extend({}, props, { attributes: { globalCompositeOperation: 'source-atop', globalAlpha: 0.8 } });
|
||||||
|
_drawImage(frame.ctx, tmpCanvas, x, y, combineProps);
|
||||||
|
});
|
||||||
|
return canvas;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = filters;
|
|
@ -289,5 +289,6 @@ class CanvasEx {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
CanvasEx,
|
CanvasEx,
|
||||||
ImageEx
|
ImageEx,
|
||||||
|
_drawImage
|
||||||
};
|
};
|
||||||
|
|
13
index.js
13
index.js
|
@ -9,6 +9,8 @@ const twemoji = require('./twemoji');
|
||||||
const app = express();
|
const app = express();
|
||||||
const config = require('./config.default.json');
|
const config = require('./config.default.json');
|
||||||
|
|
||||||
|
const filters = require('./filters.js');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_.extend(config, require('./config')); // eslint-disable-line global-require
|
_.extend(config, require('./config')); // eslint-disable-line global-require
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -113,10 +115,11 @@ function render(template, img, size, flipH) {
|
||||||
w: template.image.width * templateScale,
|
w: template.image.width * templateScale,
|
||||||
name: `template ${template.src}`,
|
name: `template ${template.src}`,
|
||||||
flipH,
|
flipH,
|
||||||
attributes: template.attributes
|
attributes: template.attributes,
|
||||||
|
filter: filters[template.filter]
|
||||||
}].sort((u, v) => u.z > v.z);
|
}].sort((u, v) => u.z > v.z);
|
||||||
|
|
||||||
const canvas = new CanvasEx(resultingWidth, resultingHeight);
|
let canvas = new CanvasEx(resultingWidth, resultingHeight);
|
||||||
|
|
||||||
for (let i = 0; i < toDraw.length; ++i) {
|
for (let i = 0; i < toDraw.length; ++i) {
|
||||||
const subject = toDraw[i];
|
const subject = toDraw[i];
|
||||||
|
@ -127,9 +130,15 @@ function render(template, img, size, flipH) {
|
||||||
transform.translate = [resultingWidth, 0];
|
transform.translate = [resultingWidth, 0];
|
||||||
transform.scale = [-1, 1];
|
transform.scale = [-1, 1];
|
||||||
}
|
}
|
||||||
|
if (subject.filter) {
|
||||||
|
canvas = subject.filter(canvas, subject.image, subject.x, subject.y, {
|
||||||
|
width: subject.w, height: subject.h, transform, attributes: subject.attributes
|
||||||
|
});
|
||||||
|
} else {
|
||||||
canvas.drawImage(subject.image, subject.x, subject.y, {
|
canvas.drawImage(subject.image, subject.x, subject.y, {
|
||||||
width: subject.w, height: subject.h, transform, attributes: subject.attributes
|
width: subject.w, height: subject.h, transform, attributes: subject.attributes
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
throw new Error(JSON.stringify({ status: 400, error: 'Invalid template' }));
|
throw new Error(JSON.stringify({ status: 400, error: 'Invalid template' }));
|
||||||
|
|
BIN
resources/PrideOverlay.png
Normal file
BIN
resources/PrideOverlay.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 78 KiB |
Reference in a new issue