0

I capture the page with Electron and try to pass this NativeImage object to a workerpool. I am passing as an PNG image since I need in this format from the worker. However, when I try to use it in Sharp, I receive an error saying ReferenceError: sharp__WEBPACK_IMPORTED_MODULE_0___default is not defined

The things I tried so far and didn't work :

  • Making NativeImage to dataUrl and pass to worker, then convert to Buffer and use it
  • Using Buffer.from() from worker and then use the image in sharp()

Here is my code from main process:

try {
      const image = await streamWindow.webContents.capturePage();
      // Send image to worker thread
      const returnVal = await pool.exec(addText, [image.toPNG()]); 

From worker:

export default function addText(image) {
  ...
  ...
  const svgBuffer = Buffer.from(svgText);
  sharp(image)
    .composite([{ input: svgBuffer, left: 200, top: 90 }])
    .toFile("./resources/test.png")
    .then((data) => {
      console.log("data ", data);
    })
    .catch((err) => {
      console.log("err ", err);
    });
}
Wokers
  • 107
  • 3
  • 13

0 Answers0