Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. var http = require('http');
  2. var qs = require('querystring');
  3. var fs = require('fs');
  4. var spawn = require('child_process').spawn;
  5.  
  6. var SCRIPT = fs.readFileSync('./script.js', { encoding: 'utf8' });
  7.  
  8. http.createServer(function (request, response) {
  9. var body = '';
  10. request.on('data', function (data) {
  11. body += data;
  12. });
  13. request.on('end', function () {
  14. var postData = qs.parse(body);
  15. var phantomOut = '';
  16. var phantom = spawn('phantomjs');
  17. phantom.stdout.on('data', function (buf) {
  18. phantomOut += buf;
  19. });
  20. phantom.on('exit', function (code) {
  21. response.writeHead(200, {
  22. 'Content-Type': 'image/png'
  23. });
  24. response.end(phantomOut);
  25. });
  26. phantom.stdin.setEncoding('utf8');
  27. phantom.stdin.write( SCRIPT.replace('(#imageData)', postData.imageData) );
  28. });
  29. }).listen(1337, '127.0.0.1');
  30.  
  31. var page = require('webpage').create();
  32. page.content = '<img src="(#imageData)">';
  33. window.setTimeout(function () {
  34. page.render('/dev/stdout', { format: 'png' });
  35. phantom.exit();
  36. }, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement