Created
December 5, 2015 06:39
-
-
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
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
#! /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