import sharp from 'sharp'; import path from 'path'; /** * Wraps text into multiple lines for SVG. */ function wrapText(text: string, maxCharsPerLine: number): string[] { const words = text.split(' '); const lines: string[] = []; let currentLine = ''; words.forEach(word => { if ((currentLine + word).length > maxCharsPerLine) { lines.push(currentLine.trim()); currentLine = word + ' '; } else { currentLine += word + ' '; } }); lines.push(currentLine.trim()); return lines; } /** * Generates a personalized business pitch card with text overlay. */ export async function generatePitchCard(text: string): Promise { const templatePath = path.resolve(__dirname, '../assets/templates/pitch_card.png'); const lines = wrapText(text.toUpperCase(), 25); const lineHeight = 60; const startY = 540 - (lines.length * lineHeight) / 2; const svgText = lines.map((line, i) => `${line}` ).join(''); const svgOverlay = Buffer.from(` MA CARTE BUSINESS MON PROJET : ${svgText} XAMLÉ - 2026 `); return sharp(templatePath) .composite([{ input: svgOverlay, top: 0, left: 0 }]) .png() .toBuffer(); }