fontmin
Minify font seamlessly

Install
$ npm install --save fontmin
Usage
var Fontmin = require('fontmin');
var fontmin = new Fontmin()
.src('fonts/*.ttf')
.dest('build/fonts')
fontmin.run(function (err, files) {
if (err) {
throw err;
}
console.log(files[0]);
});
You can use gulp-rename to rename your files:
var Fontmin = require('Fontmin');
var rename = require('gulp-rename');
var fontmin = new Fontmin()
.src('fonts/big.ttf')
.use(rename('small.ttf'));
API
new Fontmin()
Creates a new Fontmin instance.
.src(file)
Type: Array|Buffer|String
Set the files to be optimized. Takes a buffer, glob string or an array of glob strings
as argument.
.dest(folder)
Type: String
Set the destination folder to where your files will be written. If you don't set
any destination no files will be written.
.use(plugin)
Type: Function
Add a plugin to the middleware stack.
.run(cb)
Type: Function
Optimize your files with the given settings.
cb(err, files, stream)
The callback will return an array of vinyl files in files and a Readable/Writable
stream in stream
Plugins
The following plugins are bundled with fontmin:
.glyph()
Compress ttf by glyph.
var Fontmin = require('fontmin');
var fontmin = new Fontmin()
.use(Fontmin.glyph({
text: '天地玄黄 宇宙洪荒'
}));
.ttf2eot()
Convert ttf to eot.
var Fontmin = require('fontmin');
var fontmin = new Fontmin()
.use(Fontmin.ttf2eot({
clone: true
}));
.ttf2woff()
Convert ttf to woff.
var Fontmin = require('fontmin');
var fontmin = new Fontmin()
.use(Fontmin.ttf2woff({
clone: true
}));
.ttf2svg()
Convert ttf to svg.
you can use imagemin-svgo to compress svg:
var Fontmin = require('fontmin');
var svgo = require('imagemin-svgo');
var fontmin = new Fontmin()
.use(Fontmin.ttf2svg({
clone: true
}));
.use(svgo());
CLI
$ npm install -g fontmin
$ fontmin --help
Usage
$ fontmin <file> <directory>
$ fontmin <directory> <output>
$ fontmin <file> > <output>
$ cat <file> | fontmin > <output>
Example
$ fontmin fonts/* build
$ fontmin fonts build
$ fontmin foo.ttf > foo-optimized.ttf
$ cat foo.ttf | fontmin > foo-optimized.ttf
Options
-t, --text require glyphs by text
-b, --basic-text require glyphs with base chars
-f, --font-family font-family for @font-face CSS
-T, --show-time show time fontmin cost
you can use curl to generate font for a web page:
$ text=`curl www.baidu.com` && fontmin -t $text font.ttf
or you can use html-to-text to make it smaller:
$ npm install -g html-to-text
$ text=`curl www.baidu.com | html-to-text` && fontmin -t $text font.ttf
Thx