Created
December 14, 2011 14:36
-
-
Save wesbos/1476820 to your computer and use it in GitHub Desktop.
PhantomJS Screenshot
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 = new WebPage(), | |
address, output, size; | |
address = "http://www.metachunk.com/"; | |
width = 1024; height = 600; | |
output = "./screenshots/wat-"+width+"X"+height+".png"; | |
page.viewportSize = { width: width, height: height }; | |
if (phantom.args.length === 3 && phantom.args[1].substr(-4) === ".pdf") { | |
size = phantom.args[2].split('*'); | |
page.paperSize = size.length === 2 ? { width: size[0], height: size[1], border: '0px' } | |
: { format: phantom.args[2], orientation: 'portrait', border: '1cm' }; | |
} | |
page.open(address, function (status) { | |
if (status !== 'success') { | |
console.log('Unable to load the address!'); | |
} else { | |
window.setTimeout(function () { | |
page.render(output); | |
phantom.exit(); | |
}, 900); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment