Skip to content

Instantly share code, notes, and snippets.

@dukex
Created November 11, 2013 15:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dukex/7414863 to your computer and use it in GitHub Desktop.
Save dukex/7414863 to your computer and use it in GitHub Desktop.
var casper = require("casper").create(),
viewportSizes = [
[320,480],
[320,568],
[600,1024],
[1024,768],
[1280,800],
[1440,900]
],
url = casper.cli.args[0],
saveDir = url.replace(/[^a-zA-Z0-9]/gi, '-').replace(/^https?-+/, '');
casper.start();
casper.each(viewportSizes, function(self, viewportSize, i) {
var width = viewportSize[0],
height = viewportSize[1];
casper.wait(5000, function() {
this.viewport(width, height);
casper.thenOpen(url, function() {
this.echo('Opening at ' + width);
var FPfilename = saveDir + '/fullpage-' + width + ".png";
var ACfilename = saveDir + '/' + width + '-' + height + ".png";
this.captureSelector(FPfilename, 'body');
this.capture(ACfilename,{top: 0,left: 0,width: width, height: height});
this.echo('snapshot taken');
});
});
});
casper.run(function() {
this.echo('Finished captures for ' + url).exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment