(text, targetPath)
| 324 | } |
| 325 | |
| 326 | async function writeLabelImage(text, targetPath) { |
| 327 | const paddingX = 16; |
| 328 | const paddingY = 12; |
| 329 | const lineGap = 8; |
| 330 | const maxWidth = 1232; |
| 331 | let scale = 4; |
| 332 | let wrapped = wrapLabelText(text, maxWidth - paddingX * 2, scale); |
| 333 | while (wrapped.truncated && scale > 2) { |
| 334 | scale -= 1; |
| 335 | wrapped = wrapLabelText(text, maxWidth - paddingX * 2, scale); |
| 336 | } |
| 337 | |
| 338 | const textWidth = Math.max(...wrapped.lines.map(line => textPixelWidth(line, scale))); |
| 339 | const width = Math.min(maxWidth, Math.max(1, textWidth + paddingX * 2)); |
| 340 | const height = paddingY * 2 + wrapped.lines.length * 7 * scale + (wrapped.lines.length - 1) * lineGap; |
| 341 | const rgba = Buffer.alloc(width * height * 4); |
| 342 | fillRect(rgba, width, 0, 0, width, height, [0, 0, 0, 174]); |
| 343 | wrapped.lines.forEach((line, index) => { |
| 344 | drawBitmapText(rgba, width, paddingX, paddingY + index * (7 * scale + lineGap), line, scale); |
| 345 | }); |
| 346 | await fsp.writeFile(targetPath, encodePng(width, height, rgba)); |
| 347 | } |
| 348 | |
| 349 | function stitchLabel(options, tone) { |
| 350 | const parts = []; |
no test coverage detected