Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

viewport options

  • Loading branch information...
commit f996c6dd92fa5bbc106e138da6ed4b6a4e7576f6 1 parent e03cc81
@tj authored
Showing with 21 additions and 8 deletions.
  1. +11 −4 lib/rasterize.js
  2. +10 −4 routes.js
View
15 lib/rasterize.js
@@ -4,16 +4,23 @@ var exec = require('child_process').exec
, bin = app.get('phantom');
/**
- * Rasterize the given `url`, saving the
- * image to `path`, and callback `(err, stdout, stderr)`.
+ * Rasterize the given `url` and callback `(err, stdout, stderr)`.
+ *
+ * Options:
+ *
+ * - `path`: output file path
+ * - viewportWidth: viewport width
+ * - viewportHeight: viewport height
*
* @param {String} url
* @param {String} path
* @param {Function} fn
*/
-module.exports = function(url, path, fn){
- var cmd = [bin, script, url, path];
+module.exports = function(url, options, fn){
+ var cmd = [bin, script, url];
+ cmd.push(options.path);
+ cmd.push(options.viewportWidth + 'x' + options.viewportHeight);
cmd = cmd.join(' ');
exec(cmd, fn);
};
View
14 routes.js
@@ -36,13 +36,19 @@ app.get('/:url(*)', ratelimit(60, 10), function(req, res, next){
var url = utils.url(req.params.url);
if (!url) return res.send(400);
var id = utils.md5(url);
- var path = join(dir, id + '.png');
+
+ var options = {
+ path: join(dir, id + '.png')
+ , viewportWidth: 800
+ , viewportHeight: 600
+ };
+
console.log('screenshot - rasterizing %s', url);
- rasterize(url, path, function(err){
+ rasterize(url, options, function(err){
if (err) return next(err);
console.log('screenshot - rasterized %s', url);
- app.emit('screenshot', url, path, id);
- res.sendfile(path);
+ app.emit('screenshot', url, options.path, id);
+ res.sendfile(options.path);
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.