From 3c16ea34c6b4833c767e6b90a33e9e63e3a10e3e Mon Sep 17 00:00:00 2001 From: David Snelling Date: Wed, 11 Jun 2025 09:17:17 -0700 Subject: [PATCH] feat: add script for encoding images to Base64 and generating HTML output Introduced `encode-image.js` to convert images to Base64 and create corresponding HTML `` tags. Outputs a sample encoded result to `encoded-image.html`. --- .idea/codeStyles/Project.xml | 12 +++++++ .idea/codeStyles/codeStyleConfig.xml | 5 +++ CONTRIBUTING.md | 2 +- README.md | 2 +- encoded-image.html | 1 + encoded-image.txt | 1 + scripts/encode-image.js | 47 ++++++++++++++++++++++++++++ scripts/update-readme.js | 26 +++++++++++++++ 8 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 encoded-image.html create mode 100644 encoded-image.txt create mode 100644 scripts/encode-image.js create mode 100644 scripts/update-readme.js diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..a461bbfa --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..79ee123c --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3b53aa3c..860878c5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,5 @@
-Brainy Logo +Brainy Logo # Contributing to Soulcraft Brainy diff --git a/README.md b/README.md index 7819bfe4..ea435234 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@
-Brainy Logo +Brainy Logo
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE) diff --git a/encoded-image.html b/encoded-image.html new file mode 100644 index 00000000..cfc1a5e2 --- /dev/null +++ b/encoded-image.html @@ -0,0 +1 @@ +Brainy Logo \ No newline at end of file diff --git a/encoded-image.txt b/encoded-image.txt new file mode 100644 index 00000000..00a5b8c4 --- /dev/null +++ b/encoded-image.txt @@ -0,0 +1 @@ +Brainy Logo diff --git a/scripts/encode-image.js b/scripts/encode-image.js new file mode 100644 index 00000000..bb9e1dfb --- /dev/null +++ b/scripts/encode-image.js @@ -0,0 +1,47 @@ +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +// Get the directory of the current module +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +// Path to the image file +const imagePath = path.join(__dirname, '..', 'brainy.png'); + +// Read the image file +const imageBuffer = fs.readFileSync(imagePath); + +// Convert the image to base64 +const base64Image = imageBuffer.toString('base64'); + +// Get the MIME type based on file extension +const getMimeType = (filePath) => { + const ext = path.extname(filePath).toLowerCase(); + switch (ext) { + case '.png': + return 'image/png'; + case '.jpg': + case '.jpeg': + return 'image/jpeg'; + case '.gif': + return 'image/gif'; + case '.svg': + return 'image/svg+xml'; + default: + return 'application/octet-stream'; + } +}; + +const mimeType = getMimeType(imagePath); + +// Create the data URL +const dataUrl = `data:${mimeType};base64,${base64Image}`; + +// Output the complete HTML img tag +const imgTag = `Brainy Logo`; + +// Write to a file instead of console.log to avoid truncation +fs.writeFileSync(path.join(__dirname, '..', 'encoded-image.html'), imgTag); + +console.log('Base64 encoded image has been saved to encoded-image.html'); diff --git a/scripts/update-readme.js b/scripts/update-readme.js new file mode 100644 index 00000000..ac369338 --- /dev/null +++ b/scripts/update-readme.js @@ -0,0 +1,26 @@ +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +// Get the directory of the current module +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +// Paths to the files +const readmePath = path.join(__dirname, '..', 'README.md'); +const encodedImagePath = path.join(__dirname, '..', 'encoded-image.html'); + +// Read the files +const readmeContent = fs.readFileSync(readmePath, 'utf8'); +const encodedImageTag = fs.readFileSync(encodedImagePath, 'utf8'); + +// Replace the image tag in the README +const updatedReadme = readmeContent.replace( + /Brainy Logo/, + encodedImageTag +); + +// Write the updated README +fs.writeFileSync(readmePath, updatedReadme); + +console.log('README.md has been updated with the base64-encoded image.');