File size: 1,117 Bytes
2cae2a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

import { TextOverlayFont, TextOverlayFontWeight, TextOverlayStyle, getCssStyle } from "../utils/getCssStyle.mts"
import { htmlToBase64Png } from "../converters/htmlToBase64Png.mts"

// generate a PNG overlay using HTML
export async function createTextOverlayImage({
  text = "",
  textStyle = "outline",
  fontFamily = "Montserrat",
  fontSize = 10,
  fontWeight = 600,
  rotation = 0,
  width = 1024,
  height = 576
}: {
  text?: string
  textStyle?: TextOverlayStyle
  fontFamily?: TextOverlayFont
  fontSize?: number
  fontWeight?: TextOverlayFontWeight
  rotation?: number
  width?: number
  height?: number
}): Promise<{
  filePath: string
  buffer: Buffer
}> {


  const html = `<html>
  <head>${getCssStyle({
    fontFamily,
    fontSize,
    fontWeight: 600,
  })}</head>
  <body>

    <!-- main content block (will be center in the middle of the screen) -->
    <div class="content">

      <!-- main line of text -->
      <p class="${textStyle}">
        ${text}
      </p>
    </div>

  </body>
</html>`

  const result = await htmlToBase64Png({
    html,
    width,
    height,
  })

  return result;
};