You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
922 B
27 lines
922 B
2 years ago
|
"use strict";
|
||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||
|
};
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.extTypeMap = void 0;
|
||
|
const fs_1 = __importDefault(require("fs"));
|
||
|
const path_1 = __importDefault(require("path"));
|
||
|
exports.extTypeMap = {
|
||
|
'.png': 'image/png',
|
||
|
'.gif': 'image/gif',
|
||
|
'.jpg': 'image/jpeg',
|
||
|
'.jpeg': 'image/jpeg',
|
||
|
'.bm': 'image/bmp',
|
||
|
'.bmp': 'image/bmp',
|
||
|
'.webp': 'image/webp',
|
||
|
'.ico': 'image/x-icon',
|
||
|
'.svg': 'image/svg+xml'
|
||
|
};
|
||
|
function image2uri(file) {
|
||
|
const image = fs_1.default.readFileSync(file);
|
||
|
const ext = path_1.default.extname(file);
|
||
|
const contentType = exports.extTypeMap[ext] || 'image/jpeg';
|
||
|
return `data:${contentType};base64,${image.toString('base64')}`;
|
||
|
}
|
||
|
exports.default = image2uri;
|
||
|
//# sourceMappingURL=index.js.map
|