public
Last active

PhantomJS Media Query Screenshot

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
var page = new WebPage(),
address, output, size;
 
address = "http://www.wesbos.com/";
width = 1024; height = 600;
output = "./screenshots/screenshot-"+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);
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.