Last active
May 27, 2022 01:38
-
-
Save spion/4759297 to your computer and use it in GitHub Desktop.
Take website screenshots of any resolution using phantomjs
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
// Usage: phantomjs screenshot.js 1920x1080 site.domain.com | |
// outputs to site.domain.com-1920x1080.png | |
// dont add http to the URL | |
// If the page didnt render in time add a delay argument | |
// e.g. 3000 for 3 seconds | |
var page = require('webpage').create(); | |
var args = require('system').args; | |
var wh = args[1].split('x'); | |
var pg = args[2]; | |
page.viewportSize = { width: wh[0], height: wh[1] }; | |
page.open('http://'+pg+'/', function () { | |
window.setTimeout(function() { | |
page.render(pg.replace('/','-') + '-'+args[1]+'.png'); | |
phantom.exit(); | |
}, args[3] || 500); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment