Skip to content

Instantly share code, notes, and snippets.

@vahan-hartooni
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vahan-hartooni/b0954ae67767ef830eec to your computer and use it in GitHub Desktop.
Save vahan-hartooni/b0954ae67767ef830eec to your computer and use it in GitHub Desktop.
// This phantomJS script takes these arguments:
// [url] [pageWidth] [pageHeight] [output filename]
// System module so we can access the arguments
var system = require('system'),
// Initialize webpage
page = require('webpage').create(),
// Set our arguments
url = system.args[1] ? system.args[1] : 'http://www.html5zombo.com',
pageWidth = system.args[2] ? parseInt(system.args[2], 10) : 960,
pageHeight = system.args[3] ? parseInt(system.args[3], 10) : 720,
output = system.args[4] ? system.args[4] : 'screenshot.png';
// Set the resolution
page.viewportSize = { width: pageWidth, height: pageHeight };
page.open(url, function(status) {
if (status !== 'success') {
console.log('Unable to access network');
phantom.exit(1);
} else {
// Where the screenshot is actually created
page.render(output);
phantom.exit();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment