var gm = require('gm').subClass({ imageMagick: true });
var fs = require('fs');

/**
 * Set defaults
 * @type {{imageType: String("png"), bg_color: String("999"), fg_color: String("666")}}
 */
var defaults = {
  imageType: "png",
  bgColor: "e1e1e1",
  color: "181818"
};

var max_age = 3153600;
var expiryDate = new Date(0);


module.exports = function(app){
  app.get('/gen/:dimension.:imageType', function(req, res, next) {
    var dim = req.params.dimension.split('x');
    var width, height, foreground, background, imageType, text;

    if(dim.length === 1) {
      width = height = dim[0] * 1;
    } else {
      width = dim[0] * 1;
      height = dim[1] * 1;
    }
    if(isNaN(width) || isNaN(height)) return next();


    if(typeof req.query.color !== 'undefined') {
      foreground = req.query.color;
    } else {
      foreground = defaults.color;
    }
    if(foreground[0] !== '#') foreground = '#' + foreground;


    if(typeof req.query.bg !== 'undefined') {
      background = req.query.bg;
    } else {
      background = defaults.bgColor;
    }
    if(background[0] !== '#') background = '#' + background;


    if(typeof req.params.imageType !== 'undefined') {
      imageType = req.params.imageType;
    } else {
      imageType = defaults.imageType;
    }
    imageType = imageType.toLowerCase();

    if(typeof req.query.text !== 'undefined') {
      // TODO handle case when the text is too long for the image
      text = req.query.text;
      //text = width + " x " + height;
    } else {
      text = width + " x " + height;
    }

    res.setHeader("Content-Type", "image/" + imageType);
    res.setHeader("Cache-Control", "public, max-age=" + max_age)
    res.setHeader("Expires", expiryDate);
    res.setHeader("Last-Modified", expiryDate);

    gm(width, height, background)
      .fill(foreground)
      .font("Arial", 20)
      .drawText(0, 0, text, "center")
      .toBuffer(imageType, function(err, buffer) {
        if(err) {
          console.log(err);
          next();
        }
        res.send(buffer);
      });

  });
};
@@ -529,17 +529,156 @@
 pe, text
-;
+, delay;%0A%0A      if (typeof req.query.delay !== %22undefined%22) %7B%0A        delay = req.query.delay;%0A      %7D else %7B%0A        delay = false;%0A      %7D
 %0A%0A    if
@@ -2163,25 +2163,172 @@
     
-res.send(buffer);
+if (delay) %7B%0A            setTimeout(function() %7B%0A              res.send(buffer);%0A            %7D, delay);%0A          %7D else %7B%0A            res.send(buffer);%0A          %7D
 %0A   
@@ -2343,8 +2343,9 @@
   %7D);%0A%7D;
+%0A

Update home.js