0

I am developing a website using Spring MVC. I have a form where I ask user for his website's URL. I need to show him the screenshot of the website after he enters its URL.

Should I generate the image at the backend or the frontend?

I do need to show the image to the user on his dashboard. I can't decide if I should generate it each time or store it at the backend. Storing at the backend will be better for performance whereas generating it everytime will show the current screenshot to the user.

Vineet
  • 1,139
  • 1
  • 11
  • 20

1 Answers1

2

Take a look to PhantomJS. You can generate png screenshot throught command line.

Here's a script for PhantomJS which take two input arguments (url and output file):

var page = require('webpage').create();
var args = require('system').args;

var web_url = args[1];
var file_name = args[2];

page.viewportSize = { width: 1200, height: 1602 };
page.clipRect = {top:0, left: 0, width: 1200, height: 1602 };

page.open(web_url, 'GET', function () {

page.evaluate(function() {
    document.body.bgColor = 'white';
});
var ret = page.render(file_name);

var exitcode = 0;
if(ret) exitcode = 1;

phantom.exit(exitcode);
});

And then you can call to PhantomJS like this:

phantomjs scriptfile.js http://www.myweb.com outputfile.png
Carlos Mayo
  • 2,054
  • 1
  • 19
  • 35