Skip to content

Commit

Permalink
filmStrip: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
macbre committed Oct 2, 2013
1 parent f7635ae commit fce4b0e
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions modules/filmStrip/filmStrip.js
@@ -0,0 +1,63 @@
/**
* Renders a serie of screenshots of page being loaded
*
* Run phantomas with --film-strip option to use this module
*/
exports.version = '0.1';

exports.module = function(phantomas) {
if (!phantomas.getParam('film-strip')) {
phantomas.log('To enable screenshots of page being loaded run phantomas with --film-strip option');
return;
}

var zoomFactor = 0.5;
//phantomas.setZoom(zoomFactor);

var util = phantomas.require('util'),
// throttling
SCREENSHOTS_MIN_INTERVAL = 75,
lastScreenshot = 0,
start = Date.now(),
// stats
timeTotal = 0,
screenshotsTotal = 0;

function screenshot() {
var now = Date.now(),
path;

// check when was the last screenshot taken (exclude time it took to render the screenshot)
if (now - lastScreenshot < SCREENSHOTS_MIN_INTERVAL) {
//phantomas.log('Film strip: skipped');
return;
}

path = util.format('filmstrip/screenshot-%d-%d.png', start, now - start - timeTotal);

phantomas.render(path);
lastScreenshot = Date.now();

phantomas.log('Film strip: rendered to %s in %d ms...', path, Date.now() - now);

// stats
timeTotal += (Date.now() - now);
screenshotsTotal++;
}

// bind to events to render screenshots on
[
'loadStarted',
'send',
'recv',
'loadFinished',
'report'
].forEach(function(ev) {
phantomas.on(ev, screenshot);
});

// print-out stats
phantomas.on('report', function() {
phantomas.log('Film strip: spent %d ms on rendering %d screenshots', timeTotal, screenshotsTotal);
});
};

0 comments on commit fce4b0e

Please sign in to comment.