Skip to content

Instantly share code, notes, and snippets.

@andriilive
Last active August 15, 2024 17:22
Show Gist options
  • Save andriilive/9c1ca0648f798a05c52d3aa3f5697729 to your computer and use it in GitHub Desktop.
Save andriilive/9c1ca0648f798a05c52d3aa3f5697729 to your computer and use it in GitHub Desktop.
JS Utils

JS Utils

imgVcard.cjs - inline image for vCard avatar

const fs = require('fs');
function encodeImageToBase64(filePath) {
try {
const image = fs.readFileSync(filePath)
const base64Image = new Buffer.from(image).toString('base64');
const vCardImageString = `PHOTO;ENCODING=b;TYPE=JPEG:${base64Image}`;
console.log(vCardImageString);
}
catch (error) {
console.error(error);
}
}
encodeImageToBase64("./ava.jpeg");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment