Giter VIP home page Giter VIP logo

pixel-fonts's Introduction

js-pixel-fonts

Pixel fonts in pure JS

npm version

Sample of Seven plus font

Installation

npm install js-pixel-fonts --save

Usage

Examples

Render as an array of pixels, for using elsewhere (e.g. drawing to canvas, controlling LEDs):

const { fonts, renderPixels } = require('js-pixel-fonts');

const pixels = renderPixels("Hi!", fonts.sevenPlus);

/**
 * pixels === [
 *   [ 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1 ],
 *   [ 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 ],
 *   [ 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1 ],
 *   [ 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1 ],
 *   [ 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1 ],
 *   [ 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0 ],
 *   [ 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1 ]
 * ]
 */

Render as a PNG: see samples.js.

API

fonts

Set of available fonts. Each font has a glyphs property describing the font, but all you need to do is pass the whole font object into one of the render... methods.

renderPixels(text, font)

Renders the supplied text string in the specified font as an array of arrays of pixels. Each array represents a single row, with each element (1 or 0) representing whether the pixel should be active or not.

renderImage(text, font, renderOptions)

Renders the supplied text string in the specified font as an image. Returns a stream of PNG data that can be piped to a file or elsewhere. fontOptions takes the following properties:

  • foreground: array of RGB(A) values, 0-255 (alpha channel defaults to 255 if not specified) for the text colour
  • background: array of RGB(A) values, 0-255 (alpha channel defaults to 255 if not specified) for the background colour of the image
  • scale (default 1): scaling factor (number of pixels per single pixel in the underlying font)

pixel-fonts's People

Contributors

hgcummings avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.