Skip to content

Instantly share code, notes, and snippets.

@arth2o
Created December 5, 2015 06:39
Show Gist options
  • Save arth2o/a8802216271ffa7cb253 to your computer and use it in GitHub Desktop.
Save arth2o/a8802216271ffa7cb253 to your computer and use it in GitHub Desktop.
With PhantomJs you can capture website and save by png. e.g.: call: phantomjs capture.js url width height outputFileName
#! /usr/bin/phantomjs
var page = require('webpage').create();
var system = require('system');
var args = system.args;
if(args[1]==''){
console.log('Url parameter is missign!')
console.log('Important to call this file for four parameters.');
console.log('phantomjs url w h output file name');
phantom.exit();
}
if(args[2]==''){
console.log('Width parameter is missign!')
console.log('Important to call this file for four parameters.');
console.log('phantomjs url w h output file name');
phantom.exit();
}
if(args[3]==''){
console.log('Height parameter is missign!')
console.log('Important to call this file for four parameters.');
console.log('phantomjs url w h output file name');
phantom.exit();
}
if(args[4]==''){
console.log('Output parameter is missign!')
console.log('Important to call this file for four parameters.');
console.log('phantomjs url w h output file name');
phantom.exit();
}
console.log(args[1], args[2], args[3], args[4]);
var savedImagePath = "/path/to/your/tmp/folder/" + args[4]
page.viewportSize = { width: args[2], height: args[3] };
page.open(args[1], function(status) {
if (status !== 'success') {
phantom.exit();
} else {
window.setTimeout(function () {
page.render(savedImagePath);
console.log(savedImagePath);
phantom.exit();
}, 1000); // Change timeout as required to allow sufficient time
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment