Created
March 16, 2023 11:06
-
-
Save neuthral/72e1ff9e6c72893bf2fab4a29c8055dc to your computer and use it in GitHub Desktop.
js encode image data to ascii and back to Uint8Array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
let imageFile = fs.readFileSync('image.jpg', null).buffer | |
let imgArray = new Uint8Array(imageFile) | |
let text = '' | |
imgArray.forEach(n => { | |
text += String.fromCharCode(n + 256) | |
}) | |
console.table(imgArray, text, '\n') | |
let arr = [] | |
for (let i = 0; i < text.length; i++) { | |
arr[i] = text.charCodeAt(i) - 256 | |
} | |
console.table(new Uint8Array(arr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment