Skip to content

Instantly share code, notes, and snippets.

@chearon
Last active May 5, 2016 14:12
Show Gist options
  • Save chearon/288bfec407ed09dfbaa8edc201a94902 to your computer and use it in GitHub Desktop.
Save chearon/288bfec407ed09dfbaa8edc201a94902 to your computer and use it in GitHub Desktop.
Test node-canvas#prefer-pango w google fonts
G_FONTS_DIR=gfonts
NODE_CANVAS_DIR="./node-canvas"
mkdir -p pngs
find $G_FONTS_DIR -name '*.ttf' | while read i; do
echo $i;
cat <<EOT | node
var path = require('path'),
Canvas = require('$NODE_CANVAS_DIR'),
fs = require('fs'),
font = '$i';
Canvas.registerFont(font, {family: 'YeaYeaYea'});
var canvas = new Canvas(320, 320);
var ctx = canvas.getContext('2d');
ctx.font = '50px YeaYeaYea';
ctx.fillText('The quick brown', 0 , 70);
ctx.fillText('fox jumped over', 0 , 140);
ctx.fillText('the lazy dog', 0 , 210);
var out = fs.createWriteStream(__dirname + '/pngs/' + path.basename(font) + '.png');
var stream = canvas.createPNGStream();
stream.on('data', function(chunk){
out.write(chunk);
});
EOT
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment