🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis
Socket
Book a DemoInstallSign in
Socket

fontmin

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fontmin

Minify font seamlessly, get required glyph from ttf, convert to ttf, eot, woff, svg

Source
npmnpm
Version
0.4.5
Version published
Weekly downloads
8.7K
-19.75%
Maintainers
1
Weekly downloads
 
Created
Source

fontmin

Minify font seamlessly

NPM version Build Status Downloads Dependencies

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]);
    // => { contents: <Buffer 00 01 00 ...> }
});

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.
  • ttf2eot — Convert ttf to eot.
  • ttf2woff — Convert ttf to woff.
  • ttf2svg — Convert ttf to svg.

.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

Keywords

font

FAQs

Package last updated on 13 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts