(width: number, height: number)
| 6 | } |
| 7 | |
| 8 | const createCanvasImageUrl = (width: number, height: number): string => { |
| 9 | const canvas = document.createElement("canvas"); |
| 10 | canvas.width = width; |
| 11 | canvas.height = height; |
| 12 | |
| 13 | const ctx = canvas.getContext("2d"); |
| 14 | if (!ctx) { |
| 15 | return `https://placehold.co/${width}x${height}`; |
| 16 | } |
| 17 | |
| 18 | ctx.fillStyle = "#f5f5f5"; |
| 19 | ctx.fillRect(0, 0, width, height); |
| 20 | |
| 21 | const fontSize = Math.max(12, Math.floor(width * 0.15)); |
| 22 | ctx.font = `bold ${fontSize}px Inter, Arial, Helvetica, sans-serif`; |
| 23 | ctx.fillStyle = "#888888"; |
| 24 | |
| 25 | const text = `${width} x ${height}`; |
| 26 | const textWidth = ctx.measureText(text).width; |
| 27 | const x = (width - textWidth) / 2; |
| 28 | const y = (height + fontSize) / 2; |
| 29 | |
| 30 | ctx.fillText(text, x, y); |
| 31 | |
| 32 | return canvas.toDataURL(); |
| 33 | }; |
| 34 | |
| 35 | export function replaceExternalImagesWithCanvas(html: string): string { |
| 36 | return html.replace( |
no outgoing calls
no test coverage detected