Last active
May 5, 2016 14:12
-
-
Save chearon/288bfec407ed09dfbaa8edc201a94902 to your computer and use it in GitHub Desktop.
Test node-canvas#prefer-pango w google fonts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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