From 714d0351eabcc1da2da9ccbd9ec9b0ba7bb9bf41 Mon Sep 17 00:00:00 2001 From: Madison Grubb Date: Thu, 4 Sep 2025 23:02:28 -0400 Subject: [PATCH] fix png compression --- README.md | 3 ++- compressPng.js | 27 --------------------------- imageGenerator.js | 4 ---- 3 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 compressPng.js diff --git a/README.md b/README.md index 49a0bee..adad81f 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,13 @@ Scrollsmith is a Node.js tool for generating Dungeons & Dragons one-page dungeon - Node.js 22+ - Ollama server running and accessible -- Nextcloud (optional) for PDF uploads +- Gitea Releases (optional) for PDF uploads - `.env` file with: ```env OLLAMA_API_URL=http://localhost:3000/api/chat/completions OLLAMA_API_KEY=your_api_key_here +COMFYUI_URL=http://192.168.1.124:8188 ```` --- diff --git a/compressPng.js b/compressPng.js deleted file mode 100644 index c4c4567..0000000 --- a/compressPng.js +++ /dev/null @@ -1,27 +0,0 @@ -import fs from 'fs/promises'; -import UPNG from 'upng-js'; - -const countUniqueColors = (data) => { - const uniqueColors = new Set(); - for (let i = 0; i < data.length; i += 4) { - uniqueColors.add(`${data[i]},${data[i + 1]},${data[i + 2]},${data[i + 3]}`); - if (uniqueColors.size > 256) { - return uniqueColors.size; - } - } - return uniqueColors.size; -}; - -export async function compressPng (filePath) { - const buffer = await fs.readFile(filePath); - const arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength); - const img = UPNG.decode(arrayBuffer); - const rgba = new Uint8Array(img.data); - const frameData = new Uint8Array(img.width * img.height * 4); - frameData.set(rgba.subarray(0, frameData.length)); - const cnum = countUniqueColors(rgba) <= 256 ? 256 : 0; - const optimizedArrayBuffer = UPNG.encode([frameData.buffer], img.width, img.height, cnum, img.depth); - const optimizedBuffer = Buffer.from(optimizedArrayBuffer); - await fs.writeFile(filePath, optimizedBuffer); - return filePath; -}; diff --git a/imageGenerator.js b/imageGenerator.js index e5bc05f..1a76735 100644 --- a/imageGenerator.js +++ b/imageGenerator.js @@ -2,7 +2,6 @@ import path from "path"; import { mkdir, writeFile } from "fs/promises"; import { fileURLToPath } from "url"; import { callOllama } from "./ollamaClient.js"; -import { compressPng } from "./compressPng.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const COMFYUI_URL = process.env.COMFYUI_URL || "http://localhost:8188"; @@ -182,9 +181,6 @@ async function generateImageViaComfyUI(prompt, filename) { console.log("Downloading image..."); const filepath = await downloadImage(comfyFilename, filename); - - console.log("Compressing PNG..."); - await compressPng(filepath); return filepath; } catch (err) {