-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplay.js
53 lines (42 loc) · 1.32 KB
/
play.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Generates full page screenshots
var page = new WebPage();
// check params
if (phantom.args.length != 4) {
console.log('Check your params.');
phantom.exit();
}
// get params
var address = phantom.args[0];
var outputFolder = phantom.args[1];
var from = parseInt(phantom.args[2]);
var to = parseInt(phantom.args[3]);
// control size
var width = from;
var i = 1;
// open page
page.viewportSize = { width: width, height: 1 };
page.clipRect = { top: 0, left: 0, width: to, height: to * 75 / 100 };
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
console.log('Page opened: ' + address);
page.evaluate(function() {
document.body.bgColor = 'white';
});
window.setTimeout(function () {
// render current size
console.log('Rendering at ' + width + ' width.');
page.render(outputFolder + '/img' + ("" + (i + 10000)).substring(1) + '.png');
// resize to next size
width += 1;
i += 1;
page.viewportSize = { width: width, height: 1 };
if (width <= to) {
setTimeout(arguments.callee, 1);
} else {
phantom.exit();
}
}, 2000);
}
});