fonteditor-core
Version:
fonts (ttf, woff, woff2, eot, svg, otf) parse, write, transform, glyph adjust.
20 lines (18 loc) • 526 B
JavaScript
/**
* @file svg字符串转base64编码
* @author mengke01(kekee000@gmail.com)
*/
/**
* svg字符串转base64编码
*
* @param {string} svg svg对象
* @param {string} scheme 头部
* @return {string} base64编码
*/
export default function svg2base64(svg, scheme = 'font/svg') {
if (typeof btoa === 'undefined') {
return 'data:' + scheme + ';charset=utf-8;base64,'
+ Buffer.from(svg, 'binary').toString('base64');
}
return 'data:' + scheme + ';charset=utf-8;base64,' + btoa(svg);
}