Last active
August 29, 2015 14:08
-
-
Save Sekhmet/ae586ff4b1d4f75a0562 to your computer and use it in GitHub Desktop.
Capture one element
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 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