Skip to content

Instantly share code, notes, and snippets.

@appnus
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save appnus/3363e8e5c276aac9e639 to your computer and use it in GitHub Desktop.

Select an option

Save appnus/3363e8e5c276aac9e639 to your computer and use it in GitHub Desktop.
Web Screenshots using PhantomJS
var page = require('webpage').create();
var system = require('system');
if (system.args.length !== 6) {
console.log('Usage: phantomjs ' + system.args[0] + ' [source] [destination] [width] [height] [delay]');
phantom.exit(1);
}
//page.settings.javascriptEnabled = false;
page.viewportSize = { width: system.args[3], height: system.args[4] };
page.open(system.args[1], function (status) {
if (status !== "success") {
console.log('Unable to resolve address: ' + system.args[1].replace(/http(s)?:\/\//, ''));
phantom.exit(1);
}
window.setTimeout(function() {
page.evaluate(function() {
// fix: if no backgroundColor set on body, background renders transparent / black
if (getComputedStyle(document.body, null).backgroundColor === "rgba(0, 0, 0, 0)") {
document.body.style.backgroundColor = "white";
}
});
page.render(system.args[2]);
page.close();
phantom.exit();
}, system.args[5]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment