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 `<img>` tags. Outputs a sample encoded result to `encoded-image.html`.
This commit is contained in:
parent
4e15237a17
commit
3c16ea34c6
8 changed files with 94 additions and 2 deletions
12
.idea/codeStyles/Project.xml
generated
Normal file
12
.idea/codeStyles/Project.xml
generated
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JSCodeStyleSettings version="0">
|
||||
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
||||
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
||||
</JSCodeStyleSettings>
|
||||
<TypeScriptCodeStyleSettings version="0">
|
||||
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
||||
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
||||
</TypeScriptCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<div align="center">
|
||||
<img src="brainy.png" alt="Brainy Logo" width="200"/>
|
||||
<img src="https://raw.githubusercontent.com/soulcraft-research/brainy/main/brainy.png" alt="Brainy Logo" width="200"/>
|
||||
|
||||
# Contributing to Soulcraft Brainy
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<div align="center">
|
||||
|
||||
<img src="brainy.png" alt="Brainy Logo" width="200"/>
|
||||
<img src="https://raw.githubusercontent.com/soulcraft-research/brainy/main/brainy.png" alt="Brainy Logo" width="200"/>
|
||||
<br/>
|
||||
|
||||
[](LICENSE)
|
||||
|
|
|
|||
1
encoded-image.html
Normal file
1
encoded-image.html
Normal file
File diff suppressed because one or more lines are too long
1
encoded-image.txt
Normal file
1
encoded-image.txt
Normal file
File diff suppressed because one or more lines are too long
47
scripts/encode-image.js
Normal file
47
scripts/encode-image.js
Normal file
|
|
@ -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 = `<img src="${dataUrl}" alt="Brainy Logo" width="200"/>`;
|
||||
|
||||
// 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');
|
||||
26
scripts/update-readme.js
Normal file
26
scripts/update-readme.js
Normal file
|
|
@ -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(
|
||||
/<img src="brainy\.png" alt="Brainy Logo" width="200"\/>/,
|
||||
encodedImageTag
|
||||
);
|
||||
|
||||
// Write the updated README
|
||||
fs.writeFileSync(readmePath, updatedReadme);
|
||||
|
||||
console.log('README.md has been updated with the base64-encoded image.');
|
||||
Loading…
Add table
Add a link
Reference in a new issue