Skip to content

Instantly share code, notes, and snippets.

@sbycrosz
Created June 16, 2014 04:42
Show Gist options
  • Save sbycrosz/7951b861f2dfcde17768 to your computer and use it in GitHub Desktop.
Save sbycrosz/7951b861f2dfcde17768 to your computer and use it in GitHub Desktop.
Local image placeholder service
// Local image placeholder service
// Usage: <img src="http://localhost:9999/300/400" />
var express = require('express'),
app = express(),
gm = require('gm');
app.get('/:width/:height', function(request, response){
var width = request.params.width,
height = request.params.height,
fontSize = Math.min( Math.min(width, height) / 4.0, width / 6 ),
dimensionText = width + " x " + height;
gm(width, height, "#157ad3")
.fontSize(fontSize)
.fill("#fff")
.drawText(0, 0, dimensionText, "Center")
.stream('png')
.pipe(response);
});
var server = app.listen(9999);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment