-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshots.js
executable file
·60 lines (53 loc) · 1.64 KB
/
screenshots.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
54
55
56
57
58
59
60
// PhantomJS script to generate screenshots of a stylesheet across
// several Plans pages / interfaces.
//
// usage: phantomjs screenshots.js
//
// dependency: python previews.py must be run prior to this script.
// fs module
var fs = require('fs');
// interfaces x pages
var interfaces = ['modern', 'postmodern', 'centered', 'postcentered'];
p = fs.open('pages.json', "r");
var pages = JSON.parse(p.read());
// sheets to render
f = fs.open('sheets.json', "r");
var sheets = JSON.parse(f.read());
// set up phantom
var page = require('webpage').create()
page.viewportSize = { width: 1024, height: 768 };
// construct queue of screenshots to be rendered
shots = new Array();
for (var j in pages) {
for (var i in interfaces) {
for (var s in sheets) {
shots.push({
'interf': interfaces[i],
'page': pages[j],
'style': s,
});
}
}
}
console.log('Rendering ' + shots.length + ' screenshots');
// application loop
var lock = false;
var interval = setInterval(function() {
if (!lock && shots.length > 0) {
lock = true;
var shot = shots.shift()
var fn = shot.page + '.' + shot.interf + '.html';
console.log('Rendering: ' + fn + ' in ' + shot.style);
// load html file
page.open('previews/' + shot.style + '/' + fn, function() {
// render png
page.render('screenshots/' + shot.style + '/' + fn + ".png");
console.log('done.');
lock = false;
});
}
if (!lock && shots.length == 0) {
console.log("image render complete!");
phantom.exit();
}
}, 250);