Coder Social home page Coder Social logo

randombits-dev / font-previews Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 5.67 MB

Contains font preview images for Google Fonts, for use in Font Pickers

Home Page: https://www.npmjs.com/package/font-previews

License: MIT License

JavaScript 100.00%
font-picker fonts generator google-fonts preview

font-previews's Introduction

Font Previews

Preview images of Google Fonts, for use in font pickers, etc.

Output Files

The output/google-fonts.json file contains metadata for the normal style/weight of all the fonts:

{
  "name": "ABeeZee",
  "category": "Sans Serif",
  "popularity": 175,
  "trending": 657,
  "dateAdded": "2012-09-30",
  "img": "abeezee-normal-400.webp",
  "base64": "UklGRqQCAABXRUJQ..."
}

The output/google-fonts-all-styles.json file contains metadata for every style/weight of every font:

{
  "name": "ABeeZee",
  "category": "Sans Serif",
  "popularity": 175,
  "trending": 657,
  "dateAdded": "2012-09-30",
  "styles": [
    {
      "img": "abeezee-normal-400.webp",
      "type": "normal",
      "weight": 400,
      "img": "abeezee-normal-400.webp",
      "base64": "UklGRqQCAABXRUJQ..."
    },
    {
      "img": "abeezee-italic-400.webp",
      "type": "italic",
      "weight": 400,
      "base64": "UklGRqQCAABXRUJQ..."
    }
  ]
}

Each font references the webp image name, and also includes the base64 encoded image data.

How the images were generated

  1. The entire Google Font data was downloaded from here.
  2. The METADATA.pb files for each font was parsed.
  3. Using puppeteer, an HTML page was rendered for each font, displaying the font name in that font. The HTML page was then captured as a screenshot.
  4. The screenshot was saved as both a webp image and a base64 encoded string.
  5. The font list was written to a JSON file, which included the base64 encoded image data, and references the name of the webp image.

How to use the data

It is recommended that you filter and/or condense the data to reduce the file size. For example, you will want to choose to either the webp or base64 image data, and remove the other. You probably also want to remove the extra metadata that is not needed for your use case.

You can create a nodejs script in your project that imports the data, and modifies it:

import fontList from 'font-previews/output/google-fonts.json' assert {type: 'json'};
import fs from 'node:fs';

// sort by popularity
const sorted = fontList.sort((a, b) => {
  return a.popularity - b.popularity;
});

// only include data we need
const newData = sorted.map(font => {
  return [
    font.name,
    font.category,
    font.base64
  ];
});

fs.writeFileSync('newData.json', JSON.stringify(newData));

font-previews's People

Contributors

nienow avatar

Watchers

 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.