Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created July 2, 2012 23:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/3036472 to your computer and use it in GitHub Desktop.
Save tmcw/3036472 to your computer and use it in GitHub Desktop.
var Canvas = require('canvas');
var fs = require('fs');
var path = require('path');
var _ = require('./underscore.string.js');
var post_dir = '/Users/tmcw/Sites/tmcw.github.com/_posts/';
var posts = fs.readdirSync(post_dir);
var txt = posts.filter(function(f) {
return f.indexOf('.md') !== -1;
}).map(function(p) {
return fs.readFileSync(path.join(post_dir, p), 'utf8');
});
var w = 640,
h = 280;
var c = new Canvas(w, h);
var ctx = c.getContext('2d');
ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = '#000';
ctx.font = '5pt Helvetica';
ctx.globalAlpha = 0.1;
txt.map(function(t) {
var pts = _.chop(t, 200);
if (pts) pts.map(function(p, i) {
ctx.fillText(p, 5, 10 + i * 4);
});
});
fs.writeFileSync('posts.png', c.toBuffer());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment