UNPKG

stable-diffusion-client

Version:
21 lines (20 loc) 713 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toBase64 = void 0; /** * Converts an image buffer to base64 * * @param {Buffer} image image buffer to convert to base64 * @param {boolean} raw if true, returns the raw base64 string, if false, returns a data url with the base64 string * @returns {Promise<string>} base64 encoded image */ async function toBase64(image, raw = false) { if (raw) { const buffer = await image.raw().toBuffer(); return buffer.toString("base64"); } const header = "data:image/png;base64,"; const buffer = await image.png().toBuffer(); return header + buffer.toString("base64"); } exports.toBase64 = toBase64;