Created
August 3, 2012 15:10
-
-
Save derek-schaefer/3248483 to your computer and use it in GitHub Desktop.
PhantomJS Webpage Rendering
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
/* Renders a web page to an image. */ | |
var address = phantom.args[0]; | |
var outfile = phantom.args[1]; | |
var width = phantom.args[2] || 1440; | |
var height = phantom.args[3] || 900; | |
var page = new WebPage(); | |
var data = { | |
errors: [], | |
address: address, | |
outfile: outfile, | |
width: width, | |
height: height | |
}; | |
var exit_code = 0; | |
page.clipRect = {width:width, height:height}; | |
page.viewportSize = {width:width, height:height}; | |
page.open(address, function(status) { | |
data.status = status; | |
if (status === 'success') { | |
page.render(outfile); | |
} else { | |
exit_code = 1; | |
} | |
console.log(JSON.stringify(data)); | |
phantom.exit(exit_code); | |
}); | |
page.onError = function(msg, trace) { | |
data.errors.push({error:msg, trace:trace}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment