From 6fd9b756e40bd6830561494a7f56568164226799 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 17 Apr 2025 14:54:46 +0100 Subject: [PATCH] Simplify image helper --- src/helpers/ImageHelper.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/helpers/ImageHelper.ts b/src/helpers/ImageHelper.ts index 0a4aa36..79c1c6b 100644 --- a/src/helpers/ImageHelper.ts +++ b/src/helpers/ImageHelper.ts @@ -30,22 +30,21 @@ export default class ImageHelper { const filePath = path.join(process.env.DATA_DIR!, "cards", card.path); - const exists = existsSync(filePath) || card.path.startsWith("http://") || card.path.startsWith("https://"); - - if (!exists) { - AppLogger.LogError("ImageHelper/GenerateCardImageGrid", `Failed to load image from path ${card.path}`); - continue; - } - let bitmap: Bitmap; - if (card.path.startsWith("http://") || card.path.startsWith("https://")) { + if (existsSync(filePath)) { + const data = await Jimp.read(filePath); + + bitmap = data.bitmap; + } else if (card.path.startsWith("http://") || card.path.startsWith("https://")) { const response = await axios.get(card.path, { responseType: "arraybuffer" }); const buffer = Buffer.from(response.data); + const data = await Jimp.fromBuffer(buffer); - bitmap = (await Jimp.fromBuffer(buffer)).bitmap; + bitmap = data.bitmap; } else { - bitmap = (await Jimp.read(filePath)).bitmap; + AppLogger.LogError("ImageHelper/GenerateCardImageGrid", `Failed to load image from path ${card.path}`); + continue; } const imageData = Jimp.fromBitmap(bitmap);