Skip to content

Instantly share code, notes, and snippets.

@bogdanRada
Forked from moondev/shotty.js
Last active July 6, 2017 07:07
Show Gist options
  • Save bogdanRada/f4c8f9defd289d7d49d6c44b205b8f82 to your computer and use it in GitHub Desktop.
Save bogdanRada/f4c8f9defd289d7d49d6c44b205b8f82 to your computer and use it in GitHub Desktop.
//create new webpage object
var page = new WebPage();
//load the page
page.open('http://espn.go.com/nfl', function (status) {
//fire callback to take screenshot after load complete
page.render('espn.png');
//finish
phantom.exit();
});
@bogdanRada
Copy link
Author

bogdanRada commented Jul 6, 2017

To run this script, navigate to where the script lives on your server and run the following command. We run "Xvfb -screen 0 1024x768x24&" first to set the parameters of our Xvfb screen buffer. This is basically a virtual screen that allows us to emulate a window environment. Then we call the script with "DISPLAY=:0 phantomjs --load-plugins=yes shotty.js" to ensure Phantom runs in the buffer. PhantomJS will execute our script and save our screenshot in the same folder the script is in. If everything went well our screenshot of espn.com should look just like the real thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment