diff --git a/src/commands/images/animate.ts b/src/commands/images/animate.ts index c61cd0d7c..41f164a68 100644 --- a/src/commands/images/animate.ts +++ b/src/commands/images/animate.ts @@ -53,7 +53,7 @@ export const command: SlashCommand = { } const mcmeta: MCMETA = mcmetaList[style]; - const file = await animateToAttachment(await loadImage(magnified), mcmeta, `${style}.gif`); + const file = await animateToAttachment(magnified, mcmeta, `${style}.gif`); await interaction .editReply({ files: [file] }) .then((message: Message) => message.deleteButton()); diff --git a/src/helpers/functions/getTexture.ts b/src/helpers/functions/getTexture.ts index 504bf7f76..812a77e73 100644 --- a/src/helpers/functions/getTexture.ts +++ b/src/helpers/functions/getTexture.ts @@ -4,7 +4,7 @@ import { Contributor, Tokens } from "@interfaces"; import axios from "axios"; import getDimensions from "@images/getDimensions"; import { APIEmbedField, AttachmentBuilder, Guild } from "discord.js"; -import { magnifyToAttachment } from "@images/magnify"; +import { magnify, magnifyToAttachment } from "@images/magnify"; import { ISizeCalculationResult } from "image-size/dist/types/interface"; import { colors } from "@utility/colors"; import { Texture, Contribution } from "@interfaces"; @@ -84,7 +84,7 @@ export const getTexture = async (options: { .setURL(`https://webapp.faithfulpack.net/#/gallery/java/32x/latest/all/?show=${texture.id}`) .addFields({ name: "Resolution", value: `${dimension.width}×${dimension.height}` }) .setThumbnail(textureURL) - .setImage(`attachment://magnified.${animated ? "gif" : "png"}`); + .setImage(`attachment://${animated ? "animated.gif" : "magnified.png"}`); let mainContribution: Contribution; if (allContributions.length) { @@ -123,7 +123,8 @@ export const getTexture = async (options: { value: `\`\`\`json\n${JSON.stringify(mcmeta.animation)}\`\`\``, }); - files.push(await animateToAttachment(await loadImage(textureURL), mcmeta)); + const { magnified } = await magnify(textureURL, { isAnimation: true }); + files.push(await animateToAttachment(magnified, mcmeta)); } else files.push(await magnifyToAttachment(textureURL)); return { embeds: [embed], files: files, components: [textureButtons], ephemeral: false }; diff --git a/src/helpers/images/animate.ts b/src/helpers/images/animate.ts index 1fcff28f2..a18fd39db 100644 --- a/src/helpers/images/animate.ts +++ b/src/helpers/images/animate.ts @@ -1,6 +1,7 @@ -import { Canvas, Image, createCanvas } from "@napi-rs/canvas"; +import { createCanvas, loadImage } from "@napi-rs/canvas"; import GIFEncoder from "./GIFEncoder"; import { AttachmentBuilder } from "discord.js"; +import { ImageSource } from "@helpers/getImage"; export interface MCMETA { animation: { @@ -15,11 +16,12 @@ export interface MCMETA { /** * Animate a given image with a given mcmeta * @author Superboxer4, Evorp, Juknum - * @param baseCanvas tilesheet to animate + * @param origin tilesheet to animate * @param mcmeta how you want it animated * @returns animated GIF as buffer */ -export async function animate(baseCanvas: Canvas | Image, mcmeta: MCMETA): Promise { +export async function animate(origin: ImageSource, mcmeta: MCMETA): Promise { + const baseCanvas = await loadImage(origin); if (!mcmeta.animation) mcmeta.animation = {}; if (!mcmeta.animation?.width) mcmeta.animation.width = baseCanvas.width; @@ -137,7 +139,7 @@ export async function animate(baseCanvas: Canvas | Image, mcmeta: MCMETA): Promi * @returns sendable gif attachment */ export async function animateToAttachment( - baseCanvas: Image | Canvas, + baseCanvas: ImageSource, mcmeta: MCMETA, name = "animated.gif", ) {