Skip to content

Commit

Permalink
add screenshot functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mathisonian committed Jan 23, 2015
1 parent 7879832 commit 5c04a49
Show file tree
Hide file tree
Showing 7 changed files with 2,914 additions and 12 deletions.
32 changes: 31 additions & 1 deletion app/controllers/visualization.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var models = require('../models');
var Q = require('q');
var _ = require('lodash');
var webshot = require('webshot');


exports.getData = function (req, res, next) {
Expand Down Expand Up @@ -298,4 +299,33 @@ exports.pym = function (req, res, next) {
}))
});
}).fail(next);
};
};



exports.screenshot = function(req, res, next) {


var vizId = req.params.vid;
var host = req.headers.host;
var url = 'http://' + host + '/visualizations/' + vizId + '/iframe';

var width = req.query.width || 1024;
var height = req.query.height || 768;

var opts = {
screenSize: {
width: width,
height: height
}
};

webshot(url, opts, function(err, renderStream) {
res.setHeader('Content-Type', 'image/png');
renderStream.pipe(res);
});

}



3 changes: 3 additions & 0 deletions app/views/session/viz-data.jade
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
li
a(href="/visualizations/#{viz.id}/data")
| Raw Data
li
a(href="/visualizations/#{viz.id}/screenshot?width=1024&height=768")
| Take Screenshot
li
a(href="/visualizations/#{viz.id}", data-attribute="permalink")
| Internal Permalink
Expand Down
1 change: 1 addition & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = function (app) {
app.post('/js/dynamic', staticController.bundleJSForExecution);
app.post('/css/dynamic', staticController.buildSCSS);
app.get('/visualizations/:vid/public', visualization.publicRead);
app.get('/visualizations/:vid/screenshot', visualization.screenshot);
app.get('/sessions/:sid/public', session.publicRead);
app.get('/visualizations/:vid/iframe', visualization.iframe);
app.get('/visualizations/:vid/pym', visualization.pym);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"topojson": "^1.6.18",
"validator": "~3.17.0",
"view-helpers": "^0.1.5",
"webshot": "^0.15.3",
"winston": "^0.7.3",
"yargs": "^1.3.3"
}
Expand Down
Loading

0 comments on commit 5c04a49

Please sign in to comment.