-
Notifications
You must be signed in to change notification settings - Fork 10
/
deck2png.js
58 lines (47 loc) · 1.23 KB
/
deck2png.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
var webpage = require('webpage'),
page = webpage.create(),
system = require('system'),
url = system.args[1] || 'index.html',
fs = require('fs'),
imageSources = [],
imageTags;
page.onLoadFinished = function(status) {
var slideCount;
if (status !== 'success') {
console.log('Target file not found.');
phantom.exit();
}
page.viewportSize = {
width: 960,
height: 522
};
slideCount = page.evaluate(function() {
var $ = window.jQuery;
$('html').removeClass('csstransitions cssreflections');
$('html, body').css({
'width': 960,
'height': 522,
'overflow': 'hidden'
});
$.deck('.slide');
return $.deck('getSlides').length;
});
fs.makeDirectory('temp-slides');
for (var i = 0; i < slideCount; i++) {
var src = 'temp-slides/output-' + i + '.png';
imageSources.push(src);
console.log('Rendering slide #' + i);
page.render(src);
page.evaluate(function() {
var $ = window.jQuery;
$.deck('next');
});
}
imageTags = imageSources.map(function(src) {
return '<img src="' + src + '" style="dispay:block;" width="100%">';
});
var output = imageTags.join('') + '<style>*{margin:0;padding:0}</style>';
fs.write('temp-output.html', output, 'w');
phantom.exit();
};
page.open(url);