jbilcke-hf HF staff commited on
Commit
e76d9f6
1 Parent(s): 6966d41

trying things

Browse files
src/bug-in-bun/aitube_ffmpeg/overlay/htmlToBase64Png.ts CHANGED
@@ -47,45 +47,52 @@ export async function htmlToBase64Png({
47
  args: [
48
  '--no-sandbox', // for alpine
49
  '--headless',
 
 
50
  '--disable-gpu',
51
  '--disable-dev-shm-usage'
52
  ]
53
  })
54
 
55
- const page = await browser.newPage()
56
-
57
- page.setViewport({
58
- width,
59
- height,
60
- })
61
-
62
  try {
63
- await page.setContent(html)
64
-
65
- const content = await page.$("body")
66
-
67
- if (!content) { throw new Error (`coudln't find body content`) }
68
-
69
- const buffer = await content.screenshot({
70
- path: outputImagePath,
71
- omitBackground: true,
72
- captureBeyondViewport: false,
73
-
74
- // we must keep PNG here, if we want transparent backgrounds
75
- type: "png",
76
 
77
- // we should leave it to binary (the default value) if we save to a file
78
- // encoding: "binary", // "base64",
 
79
  })
80
 
81
- return {
82
- filePath: outputImagePath,
83
- buffer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
85
  } catch (err) {
86
  throw err
87
  } finally {
88
- await page.close()
89
  await browser.close()
90
  }
91
  };
 
47
  args: [
48
  '--no-sandbox', // for alpine
49
  '--headless',
50
+ '--no-zygote',
51
+ // '--single-process',
52
  '--disable-gpu',
53
  '--disable-dev-shm-usage'
54
  ]
55
  })
56
 
 
 
 
 
 
 
 
57
  try {
58
+ const page = await browser.newPage()
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
+ page.setViewport({
61
+ width,
62
+ height,
63
  })
64
 
65
+ try {
66
+ await page.setContent(html)
67
+
68
+ const content = await page.$("body")
69
+
70
+ if (!content) { throw new Error (`coudln't find body content`) }
71
+
72
+ const buffer = await content.screenshot({
73
+ path: outputImagePath,
74
+ omitBackground: true,
75
+ captureBeyondViewport: false,
76
+
77
+ // we must keep PNG here, if we want transparent backgrounds
78
+ type: "png",
79
+
80
+ // we should leave it to binary (the default value) if we save to a file
81
+ // encoding: "binary", // "base64",
82
+ })
83
+
84
+ return {
85
+ filePath: outputImagePath,
86
+ buffer
87
+ }
88
+ } catch (err) {
89
+ throw err
90
+ } finally {
91
+ await page.close()
92
  }
93
  } catch (err) {
94
  throw err
95
  } finally {
 
96
  await browser.close()
97
  }
98
  };