-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfont.js
50 lines (36 loc) · 1.22 KB
/
font.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Module dependencies.
*/
var Canvas = require('canvas')
, canvas = new Canvas(320, 320)
, Font = Canvas.Font
, ctx = canvas.getContext('2d')
, fs = require('fs')
, path = require("path");
if (!Font) {
throw new Error('Need to compile with font support');
}
function fontFile(name) {
return path.join(__dirname, '/pfennigFont/', name);
}
var pfennigFont = new Font('pfennigFont', fontFile('Pfennig.ttf'));
pfennigFont.addFace(fontFile('PfennigBold.ttf'), 'bold');
pfennigFont.addFace(fontFile('PfennigItalic.ttf'), 'normal', 'italic');
pfennigFont.addFace(fontFile('PfennigBoldItalic.ttf'), 'bold', 'italic');
var canvas = new Canvas(320, 320)
var ctx = canvas.getContext('2d')
// Tell the ctx to use the font.
ctx.addFont(pfennigFont);
ctx.font = 'normal normal 50px Helvetica';
ctx.fillText('Quo Vaids?', 0, 70);
ctx.font = 'bold 50px pfennigFont';
ctx.fillText('Quo Vaids?', 0, 140);
ctx.font = 'italic 50px pfennigFont';
ctx.fillText('Quo Vaids?', 0, 210);
ctx.font = 'bold italic 50px pfennigFont';
ctx.fillText('Quo Vaids?', 0, 280);
var out = fs.createWriteStream(__dirname + '/font-' + Date.now() + '.png');
var stream = canvas.createPNGStream();
stream.on('data', function(chunk){
out.write(chunk);
});