MCPcopy Create free account
hub / github.com/TomClive/SeeDance2Stitcher / writeLabelImage

Function writeLabelImage

server.js:326–347  ·  view source on GitHub ↗
(text, targetPath)

Source from the content-addressed store, hash-verified

324}
325
326async 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
349function stitchLabel(options, tone) {
350 const parts = [];

Callers 1

handleExportCollageFunction · 0.85

Calls 5

wrapLabelTextFunction · 0.85
textPixelWidthFunction · 0.85
fillRectFunction · 0.85
drawBitmapTextFunction · 0.85
encodePngFunction · 0.85

Tested by

no test coverage detected