This commit is contained in:
Daniel Odendahl Jr
2017-11-05 19:46:30 +00:00
parent c192b98823
commit 7870899de6
2 changed files with 7 additions and 5 deletions
+4 -2
View File
@@ -38,12 +38,14 @@ module.exports = class HeLivesInYouCommand extends Command {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'he-lives-in-you.png'));
const { body } = await snekfetch.get(avatarURL);
const avatar = await loadImage(body);
const avatarCanvas = createCanvas(avatar.width, avatar.height);
const avatarCtx = avatarCanvas.getContext('2d');
distort(avatarCtx, 0, 0, avatar.width, avatar.height);
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
ctx.rotate(-24 * (Math.PI / 180));
drawImageWithTint(ctx, avatar, '#00115d', 75, 160, 130, 150);
distort(ctx, 5, 75, 160, 130, 150);
drawImageWithTint(ctx, avatarCanvas, '#00115d', 75, 160, 130, 150);
ctx.rotate(24 * (Math.PI / 180));
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'he-lives-in-you.png' }] });
} catch (err) {
+3 -3
View File
@@ -78,12 +78,12 @@ class CanvasUtil {
}
static drawImageWithTint(ctx, image, color, x, y, width, height) {
ctx.globalAlpha = 0.5;
ctx.fillStyle = color;
ctx.fillRect(x, y, width, height);
ctx.drawImage(image, x, y, width, height);
ctx.globalAlpha = 1;
ctx.globalAlpha = 0.5;
ctx.fillRect(x, y, width, height);
ctx.fillStyle = '#000000';
ctx.globalAlpha = 1;
}
}