Estoy usando Node.js 14.18.1 y necesito crear una imagen, jpeg, con mis iniciales usando TypeScript, sin el uso de paquetes de terceros, como lienzo.
Realicé esta tarea usando lienzo, pero no se implementa bien en varios sistemas operativos en mi entorno.
Cualquier fragmento sería apreciado.
Como referencia, aquí está la función que creé usando el paquete canvas del registro npm:
const generateAvatar = ({ text, foregroundColor = 'white', backgroundColor = '#041c2c', height = 42, width = 42 }: { text: string, foregroundColor?: string, backgroundColor?: string, height?: number, width?: number }): Buffer => { const canvas = createCanvas(width, height); const context = canvas.getContext('2d'); // Draw background context.fillStyle = backgroundColor; context.fillRect(0, 0, canvas.width, canvas.height); // Draw text context.font = "1em Arial"; context.fillStyle = foregroundColor; context.textAlign = "center"; context.textBaseline = "middle"; context.fillText(text, canvas.width / 2, canvas.height / 2); const buffer = canvas.toBuffer("image/jpeg"); return buffer; }