Skip to content

Instantly share code, notes, and snippets.

@wibron
Created October 16, 2012 13:36
Show Gist options
  • Save wibron/3899350 to your computer and use it in GitHub Desktop.
Save wibron/3899350 to your computer and use it in GitHub Desktop.
Create screenshot from a webpage via PhantomJS

Take screenshots with PhantomJS

Usage:

$ phantomjs screenshot.js http://your-url.com/
var system = require('system'),
page = require('webpage').create(),
url = system.args[1],
match = /.+\.\w\w.*/;
page.viewportSize = { width: 1280, height: 1200 };
if (url.length && match.test(url)) {
page.open(system.args[1], function() {
page.render(Math.random().toString(10).substring(7) + '.png');
phantom.exit();
console.log('Saved screenshot for ' + url);
});
} else {
phantom.exit();
console.log('Incorrect URL "' + url + '"');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment