Created
November 23, 2013 08:08
-
-
Save ahomu/7612090 to your computer and use it in GitHub Desktop.
めも
This file contains hidden or 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 = require('webpage').create(), | |
system = require('system'); | |
var url = system.args[1]; | |
page.viewportSize = { | |
width : system.args[2] || 1024, | |
height: system.args[3] || 768 | |
}; | |
// @see https://github.com/ariya/phantomjs/issues/10619#issuecomment-24516046 | |
function renderCurrentViewport(page, filename) { | |
var viewportSize = page.viewportSize; | |
var scrollOffsets = page.evaluate(function() { | |
return { | |
x: window.pageXOffset, | |
y: window.pageYOffset | |
}; | |
}); | |
page.clipRect = { | |
top: scrollOffsets.y, | |
left: scrollOffsets.x, | |
height: viewportSize.height, | |
width: viewportSize.width | |
}; | |
page.render(filename); | |
} | |
page.open(url, function () { | |
renderCurrentViewport(this, './shot/'+url.replace(/\//g, '-')+'.png'); | |
phantom.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment