Created
September 30, 2012 23:28
-
-
Save ahomu/3808729 to your computer and use it in GitHub Desktop.
Create slides(Reveal.js) PNG images using phantomjs
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
console.log('Loading a web page'); | |
var page = require('webpage').create(); | |
var url = 'http://localhost:1947/'; | |
page.viewportSize = { | |
width: 1024, | |
height: 768 | |
}; | |
page.open(url, function (status) { | |
//Page is loaded! | |
var iz, i = 0, queue = {}; | |
iz = page.evaluate(function() { | |
return document.querySelector('.slides').children.length; | |
}); | |
console.log('total '+iz+' pages!'); | |
function createQueue(i) { | |
return function() { | |
console.log('rendering page of '+i+' ..............'); | |
page.evaluate(function(i) { | |
Reveal.navigateTo(i); | |
}, i); | |
// waiting transition | |
setTimeout(function() { | |
var next = queue[(i+1)]; | |
page.render('./shot/shot-'+i+'.png'); | |
if (next) { | |
next(); | |
} else { | |
phantom.exit(); | |
} | |
console.log('done '+i+'.'); | |
}, 1000); | |
}; | |
} | |
for (; i<iz; i++) { | |
queue[i] = createQueue(i); | |
} | |
queue[0](); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment