Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture desktop screen of computer host where it's running on using node.js

Is there such a way to capture desktop with node.js not a browser tab?

I have searched a lot but I didn't find any.

What I want is to use node.js to build desktop application.

like image 587
user12cdhbw7 Avatar asked Dec 14 '13 22:12

user12cdhbw7


Video Answer


2 Answers

You can use

http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

and

https://en.wikipedia.org/wiki/Scrot

to make screenshot of screen of current user running nodejs application. Something like this (it is complete expressJS example):

var express = require('express'),
  childProcess = require('child_process'),
  app = express();

app.get('/screenshot.png', function(request,response){
  childProcess.exec('scrot screenshot.png', function(err){
    if(err1) {
      response.send(503,'Error creating image!');
    } else {
       response.sendfile('screenshot.png')
    }
  });
});
app.listen(3000);

But this is quite slow approach.

like image 175
vodolaz095 Avatar answered Oct 03 '22 08:10

vodolaz095


Why don't you just call an external program?

For example, you could call import:

$ import -window root screenshot.png

The code:

var exec = require('child_process').exec;
exec('import -window root screenshot.png', function (error, stdout, stderr){
    // now you have the screenshot
});
like image 29
Pedro L. Avatar answered Oct 03 '22 08:10

Pedro L.