From 4f7d8f9fb6e27cef185551b87e7b66dc2353224e Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 24 Apr 2024 00:22:55 -0400 Subject: [PATCH] Speed up --- commands/edit-avatar/matrix.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/commands/edit-avatar/matrix.js b/commands/edit-avatar/matrix.js index 2e734215..e75e5594 100644 --- a/commands/edit-avatar/matrix.js +++ b/commands/edit-avatar/matrix.js @@ -59,12 +59,15 @@ module.exports = class MatrixCommand extends Command { encoder.setRepeat(0); encoder.setDelay(0); encoder.setQuality(200); + const distortedCanvas = createCanvas(avatar.width, avatar.height); + const distortedCtx = distortedCanvas.getContext('2d'); + distortedCtx.drawImage(avatar, 0, 0); + distort(distortedCtx, 20, 0, 0, avatar.width, avatar.height, 5); for (let i = 0; i < frameCount; i++) { const frame = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'matrix', `frame-${i}.gif`)); const ratio = frame.width / frame.height; const width = Math.round(avatar.height / ratio); - ctx.drawImage(avatar, 0, 0); - distort(ctx, 20, 0, 0, avatar.width, avatar.height, 5); + ctx.drawImage(distortedCanvas, 0, 0); ctx.drawImage(frame, avatar.width - width, 0, width, avatar.height); encoder.addFrame(ctx); }