Skip to content

Instantly share code, notes, and snippets.

@spion
Last active May 27, 2022 01:38
Show Gist options
  • Save spion/4759297 to your computer and use it in GitHub Desktop.
Save spion/4759297 to your computer and use it in GitHub Desktop.
Take website screenshots of any resolution using phantomjs
// 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