Skip to content

Instantly share code, notes, and snippets.

@gogromat
Created October 19, 2012 03:13
Show Gist options
  • Save gogromat/3916029 to your computer and use it in GitHub Desktop.
Save gogromat/3916029 to your computer and use it in GitHub Desktop.
PhantomJS - rasterize
var page = require('webpage').create(),
address,
output,
size;
if (phantom.args.length < 1) {
console.log('Error: Wrong number of parameters provided');
phantom.exit();
}
else {
address = phantom.args[0];
output = phantom.args[1];
size = phantom.args[2];
if (typeof output === 'undefined') {
output = 'output.png';
}
if (typeof size === 'undefined') {
size = [1024,768];
}
else {
size = size.split('*');
}
page.viewportSize = { width: size[0], height: size[1] };
page.open(address, function(status) {
if (status === 'success') {
console.log(output);
window.setTimeout(function(){
page.render(output);
phantom.exit();
});
}
else {
console.log('Error: Failed to load the address: ' + address);
phantom.exit();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment