Skip to content

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

@KolbySisk

Description

@KolbySisk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions