From 202137d99b2566f61fdb77e268ae9d4d632cbcdc Mon Sep 17 00:00:00 2001 From: Evorp <3vorpgaming@gmail.com> Date: Sun, 15 Oct 2023 21:31:24 -0700 Subject: [PATCH] image command consistency fixes --- src/helpers/images/animate.ts | 30 +++++++++++++++--------------- src/helpers/images/multiply.ts | 16 ++++++++-------- src/helpers/images/palette.ts | 21 ++++++++++----------- src/helpers/images/tile.ts | 6 +++--- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/helpers/images/animate.ts b/src/helpers/images/animate.ts index a18fd39db..c9eaf03a2 100644 --- a/src/helpers/images/animate.ts +++ b/src/helpers/images/animate.ts @@ -59,22 +59,22 @@ export async function animate(origin: ImageSource, mcmeta: MCMETA): Promise 1048576) return { image: null, embed: null }; - const canvas: Canvas = createCanvas(imageToDraw.width, imageToDraw.height); - const context = canvas.getContext("2d"); - context.drawImage(imageToDraw, 0, 0); + const canvas = createCanvas(imageToDraw.width, imageToDraw.height); + const ctx = canvas.getContext("2d"); + ctx.drawImage(imageToDraw, 0, 0); const allColors: AllColors = {}; - const imageData = context.getImageData(0, 0, imageToDraw.width, imageToDraw.height).data; + const imageData = ctx.getImageData(0, 0, imageToDraw.width, imageToDraw.height).data; for (let x = 0; x < imageToDraw.width; ++x) { for (let y = 0; y < imageToDraw.height; ++y) { @@ -63,7 +62,7 @@ export async function palette(origin: ImageSource) { if (!a) continue; let hex = new ColorManager({ rgb: { r, g, b } }).toHEX().value; - if (!(hex in allColors)) allColors[hex] = { hex: hex, opacity: [], rgb: [r, g, b], count: 0 }; + if (!(hex in allColors)) allColors[hex] = { hex, opacity: [], rgb: [r, g, b], count: 0 }; ++allColors[hex].count; allColors[hex].opacity.push(a); @@ -166,12 +165,12 @@ export async function palette(origin: ImageSource) { }); const colorCanvas = createCanvas(bandWidth * allColorsSorted.length, GRADIENT_HEIGHT); - const ctx = colorCanvas.getContext("2d"); + const colorCtx = colorCanvas.getContext("2d"); allColorsSorted.forEach((color, index) => { - ctx.fillStyle = `#${color.hex}`; - ctx.globalAlpha = color.opacity.reduce((acc, val, i) => (acc * i + val) / (i + 1)); // average alpha - ctx.fillRect(bandWidth * index, 0, bandWidth, GRADIENT_HEIGHT); + colorCtx.fillStyle = `#${color.hex}`; + colorCtx.globalAlpha = color.opacity.reduce((acc, val, i) => (acc * i + val) / (i + 1)); // average alpha + colorCtx.fillRect(bandWidth * index, 0, bandWidth, GRADIENT_HEIGHT); }); return { image: colorCanvas.toBuffer("image/png"), embed }; diff --git a/src/helpers/images/tile.ts b/src/helpers/images/tile.ts index d98c912a8..5ed1da58e 100644 --- a/src/helpers/images/tile.ts +++ b/src/helpers/images/tile.ts @@ -63,9 +63,9 @@ export async function tile(origin: ImageSource, options: TileOptions = {}): Prom /** * Follows this pattern: - * x x x x x x . x . . x . . . . - * x x x -> x . x -> x x x -> . x . OR x x x - * x x x x x x . x . . x . . . . + * x x x x x x . x . . x . . . . + * x x x -> x . x -> x x x -> . x . OR x x x + * x x x x x x . x . . x . . . . */ if (options?.random == "rotation") {