Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid file signature error when using buffer from nut.js #59

Open
KolbySisk opened this issue Mar 3, 2022 · 0 comments
Open

Invalid file signature error when using buffer from nut.js #59

KolbySisk opened this issue Mar 3, 2022 · 0 comments

Comments

@KolbySisk
Copy link

KolbySisk commented Mar 3, 2022

Hi all,

I'm utilizing nut.js in my project to capture the screen. I want to give the buffer from that operation to get-pixels. When I do though, I get this error:

Error: Invalid file signature
    at module.exports.Parser._parseSignature (/private/tmp/o/node_modules/get-pixels/node_modules/pngjs/lib/parser.js:53:18)
    at module.exports.ChunkStream._processRead (/private/tmp/o/node_modules/get-pixels/node_modules/pngjs/lib/chunkstream.js:174:13)
    at module.exports.ChunkStream._process (/private/tmp/o/node_modules/get-pixels/node_modules/pngjs/lib/chunkstream.js:193:14)
    at module.exports.ChunkStream.write (/private/tmp/o/node_modules/get-pixels/node_modules/pngjs/lib/chunkstream.js:61:8)
    at module.exports.ChunkStream.end (/private/tmp/o/node_modules/get-pixels/node_modules/pngjs/lib/chunkstream.js:74:10)
    at exports.PNG.PNG.end (/private/tmp/o/node_modules/get-pixels/node_modules/pngjs/lib/png.js:98:16)
    at exports.PNG.PNG.parse (/private/tmp/o/node_modules/get-pixels/node_modules/pngjs/lib/png.js:88:8)
    at handlePNG (/private/tmp/o/node_modules/get-pixels/node-pixels.js:17:7)
    at doParse (/private/tmp/o/node_modules/get-pixels/node-pixels.js:109:7)
    at getPixels (/private/tmp/o/node_modules/get-pixels/node-pixels.js:140:5) undefined

This is my code:

const { screen } = require("@nut-tree/nut-js");
const getPixels = require("get-pixels");

(async () => {
  const screenCapture = await screen.grab();
  getPixels(screenCapture.data, 'image/png', async (error, pixels) => {
      console.log(error, pixels)
    });
})();

screenCapture.data is an image buffer, which when console logged looks like:

<Buffer d5 86 f5 ff d4 86 f5 ff d4 86 f5 ff d4 86 f5 ff d4 86 f5 ff d5 86 f5 ff d4 86 f5 ff d4 86 f5 ff d4 86 f5 ff d4 86 f5 ff d4 86 f6 ff d5 87 f5 ff d4 87 ... 8294350 more bytes>

Does anyone have any advice on how to make this work, or am I running into a bug? Thanks.

@KolbySisk KolbySisk changed the title Invalid file signature error when using get-pixels with nut.js Invalid file signature error when using buffer from nut.js Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant