diff --git a/commands/pokedex/pokedex-box-sprite.js b/commands/pokedex/pokedex-box-sprite.js index 5ca9be2d..7f323342 100644 --- a/commands/pokedex/pokedex-box-sprite.js +++ b/commands/pokedex/pokedex-box-sprite.js @@ -74,7 +74,7 @@ module.exports = class PokedexBoxSpriteCommand extends Command { const y = Math.floor(this.id / 12) * 30; ctx.imageSmoothingEnabled = false; ctx.drawImage(this.client.pokemon.sprites, x, y, 40, 30, 0, 0, 250, 250); - cropToContent(ctx, canvas.width, canvas.height); + cropToContent(ctx, canvas, canvas.width, canvas.height); return msg.say(`#${pokemon.displayID} - ${pokemon.name}`, { files: [{ attachment: canvas.toBuffer(), diff --git a/structures/pokemon/Pokemon.js b/structures/pokemon/Pokemon.js index ea945a17..13948bc3 100644 --- a/structures/pokemon/Pokemon.js +++ b/structures/pokemon/Pokemon.js @@ -158,7 +158,7 @@ module.exports = class Pokemon { const x = 40 * (this.id % 12); const y = Math.floor(this.id / 12) * 30; ctx.drawImage(this.store.sprites, x, y, 40, 30, 0, 0, 40, 30); - cropToContent(ctx, canvas.width, canvas.height); + cropToContent(ctx, canvas, canvas.width, canvas.height); return canvas.toBuffer(); } diff --git a/util/Canvas.js b/util/Canvas.js index 83a18494..871c54a4 100644 --- a/util/Canvas.js +++ b/util/Canvas.js @@ -146,9 +146,9 @@ module.exports = class CanvasUtil { return ctx; } - static cropToContent(ctx, w, h) { + static cropToContent(ctx, canvas, w, h) { const pix = { x: [], y: [] }; - const imageData = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height); + const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); let index; for (let y = 0; y < h; y++) { for (let x = 0; x < w; x++) { @@ -165,8 +165,8 @@ module.exports = class CanvasUtil { const newW = (1 + pix.x[n]) - pix.x[0]; const newH = (1 + pix.y[n]) - pix.y[0]; const cut = ctx.getImageData(pix.x[0], pix.y[0], newW, newH); - ctx.canvas.width = newW; - ctx.canvas.height = newH; + canvas.width = newW; + canvas.height = newH; ctx.putImageData(cut, 0, 0); return ctx; }