Open1

SVGをNode.jsでBase64にするスクリプト

Urushihara TakeruUrushihara Takeru
// RUN: node script.js /path/to/svg | pbcopy
const fs = require("fs");

function fileToBase64(filePath) {
  const fileData = fs.readFileSync(filePath);

  const base64Data = fileData.toString("base64");

  return base64Data;
}

const filePath = process.argv.slice(2)[0];

const base64String = fileToBase64(filePath);

console.log(`data:image/svg+xml;base64,${base64String}`);