Skip to content

Instantly share code, notes, and snippets.

@Sekhmet
Last active August 29, 2015 14:08
Show Gist options
  • Save Sekhmet/ae586ff4b1d4f75a0562 to your computer and use it in GitHub Desktop.
Save Sekhmet/ae586ff4b1d4f75a0562 to your computer and use it in GitHub Desktop.
Capture one element
var async = require('async'),
sizes = [
[1280, 720],
];
function capture(sizes, callback) {
var page = require('webpage').create();
page.viewportSize = {
width: sizes[0],
height: sizes[1]
};
page.zoomFactor = 1;
page.open('http://localhost:8000/dist', function (status) {
var filename = sizes[0] + 'x' + sizes[1] + '.png';
var data = page.evaluate(function() {
return document.querySelector('section.pricing-4.inverse').getBoundingClientRect();
});
console.log(data.top);
page.clipRect = data;
page.render('./screenshots/' + filename);
page.close();
callback.apply();
});
}
async.eachSeries(sizes, capture, function (e) {
if (e) console.log(e);
console.log('done!');
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment