From 9c3ab5d9dcdd1101f875d61cde056fc625ebdff4 Mon Sep 17 00:00:00 2001 From: neo Date: Sun, 9 Nov 2025 09:11:43 -0500 Subject: [PATCH] fix(img2gif): keep original aspect ratio and filename (#487) * fix(img2gif): keep original aspect ratio and filename * remove contribution --- src/equicordplugins/imgToGif/index.tsx | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/equicordplugins/imgToGif/index.tsx b/src/equicordplugins/imgToGif/index.tsx index e6e849460..7e4a5dc06 100644 --- a/src/equicordplugins/imgToGif/index.tsx +++ b/src/equicordplugins/imgToGif/index.tsx @@ -108,8 +108,22 @@ export default definePlugin({ const avatar = await loadImage(image); - const gifHeight = height ?? DEFAULT_RESOLUTION; - const gifWidth = width ?? DEFAULT_RESOLUTION; + let gifWidth: number; + let gifHeight: number; + + if (width && height) { + gifWidth = width; + gifHeight = height; + } else if (width) { + gifWidth = width; + gifHeight = Math.round((avatar.height / avatar.width) * width); + } else if (height) { + gifHeight = height; + gifWidth = Math.round((avatar.width / avatar.height) * height); + } else { + gifWidth = avatar.width; + gifHeight = avatar.height; + } const gif = GIFEncoder(); const canvas = document.createElement("canvas"); @@ -134,7 +148,8 @@ export default definePlugin({ } gif.finish(); - const file = new File([gif.bytesView()], "converted.gif", { type: "image/gif" }); + const originalName = image.name ? image.name.replace(/\.[^/.]+$/, "") : "converted"; + const file = new File([new Uint8Array(gif.bytesView())], `${originalName}.gif`, { type: "image/gif" }); setTimeout(() => UploadHandler.promptToUpload([file], cmdCtx.channel, DraftType.ChannelMessage), 10); } catch (err) { UploadManager.clearAll(cmdCtx.channel.id, DraftType.SlashCommand);