UNPKG

woolball-client

Version:

Client-side library for Woolball enabling secure browser resource sharing for distributed AI task processing

26 lines (25 loc) 775 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.charToImage = charToImage; async function charToImage(data) { const { input } = data; const canvas = document.createElement('canvas'); const size = 128; canvas.width = size; canvas.height = size; const ctx = canvas.getContext('2d'); if (!ctx) { throw new Error('Could not get canvas context'); } ctx.fillStyle = '#FFFFFF'; ctx.fillRect(0, 0, size, size); ctx.fillStyle = '#000000'; ctx.font = `${size - 10}px sans-serif`; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(input, size / 2, size / 2); const base64Image = canvas.toDataURL('image/png'); return { image: base64Image }; }