Created
October 19, 2012 03:13
-
-
Save gogromat/3916029 to your computer and use it in GitHub Desktop.
PhantomJS - rasterize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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