This project is a system for sorting fonts according to visual similarity see blog post. It consists of three main scripts:
font_harvester.py
: Downloads Google Fonts and stores them locally. Users can also add their own fonts.font_features.py
: Computes visual features for each font.font_sort.py
: Sorts fonts based on visual similarity and produces a sorted font list and font specimens.
- Clone the repository:
git clone https://github.com/matevz-kovacic/font-sort.git
- Navigate to the project directory:
cd font-sort
- Install the dependencies:
pip install .
Download fonts from Google Fonts or add your own fonts under the fonts
directory (location of font files in format /fonts-directory-save-dir/font-name/regular.ttf
).
To download Google Fonts, you need a Google Fonts API key which can be obtained at https://developers.google.com/fonts/docs/developer_api . You can provide this API key via an environment variable or as a command-line argument.
- Environment Variable: Set the
GOOGLE_FONTS_API_KEY
environment variable with your API key.export GOOGLE_FONTS_API_KEY=your_google_fonts_api_key
- Command-Line Arguments:
python font_harvester.py --api_key your_google_fonts_api_key
--api_key
(str): Google Fonts API key. If not provided, it will be read from theGOOGLE_FONTS_API_KEY
environment variable.--save_path
(str): Directory to save the fonts. Default is./fonts
.--styles
(str, nargs='+'): Harvest only certain font styles (e.g., regular, italic, bold). Default is'regular'
.--subset
(str, nargs='+'): Harvest only subsets of fonts (e.g., latin). Default is'latin'
.
Example:
python font_harvester.py --api_key your_google_fonts_api_key --save_path ./fonts --styles regular --subset latin
Compute visual features for each font. This step generates feature vectors that are used for sorting fonts based on visual similarity and also computes average glyph density of fonts.
--font_path
(str): Directory with fonts. Default is./fonts
.--characters
(str): Characters for font comparisons in each font. Default is'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@?!'
.--texts
(str, nargs='+'): Array of texts for font comparisons. Default is'The quick brown fox jumps over the lazy dog'
.--force_features_recompute
(bool): Force features recompute. Default isTrue
.
Example:
python font_features.py --font_path ./fonts --characters 'ABCD' --texts 'Hello World' --force_features_recompute True
Sort fonts based on visual similarity and produce a sorted font list and font specimens.
--font_path
(str): Directory with fonts. Default is./fonts
.
Example:
python font_sort.py --font_path ./fonts
System-wide default parameters are stored in config.py
. You can modify this file to change default settings such as the font directory, font subsets, and styles.
This project is licensed under the MIT License.