Search by

alto / font

simonandre

Read, inspect, convert, and subset OpenType, TrueType, WOFF, and WOFF2 fonts in PHP.

Package info

github.com/altophp/font

Homepage

Documentation

pkg:composer/alto/font

Fund package maintenance!

smnandre

Statistics

Installs: 176

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v0.10.1 2026-10-17 03:22 UTC

This package is auto-updated.

Last update: 2026-10-17 04:45:53 UTC


README

ALTO Font

Inspect, convert, and subset font files from PHP. Read a font's family and style, find a matching face, or keep only the characters your application uses.

PHP Version CI Packagist License GitHub Sponsors

Read a font

Save this as inspect.php, place your font at fonts/Inter-Regular.ttf, and run php inspect.php:

<?php

require __DIR__.'/vendor/autoload.php';

use Alto\Font\Font;

$font = Font::fromFile(__DIR__.'/fonts/Inter-Regular.ttf');

printf("%s %s\n", $font->metadata()->family, $font->metadata()->subfamily);

For Inter Regular, this prints Inter Regular. See Getting started to check which characters it contains.

Installation

composer require alto/font

Requires PHP 8.4+ with Iconv and Zlib. WOFF2 adds Brotli: the PHP extension or the executable to read, and a compressor passed to the writer; see Compression.

Create a smaller font for your text

Create an output directory first. Run this as a separate script beside your vendor directory. The destination must not already exist.

<?php

require __DIR__.'/vendor/autoload.php';

use Alto\Font\Font;
use Alto\Font\Subset\SubsetOptions;
use Alto\Font\Subset\UnicodeSet;
use Alto\Font\Writer\WoffWriter;

$font = Font::fromFile(__DIR__.'/fonts/Inter-Regular.ttf');
$result = $font->subset(new SubsetOptions(
    UnicodeSet::fromText('ALTO Font 0123456789'),
));

$destination = __DIR__.'/output/inter-subset.woff';
new WoffWriter()->write($result->font, $destination);

printf("Saved inter-subset.woff (%d bytes)\n", filesize($destination));

This creates a WOFF file with the requested characters and the glyphs they depend on; the original file is unchanged. Use the complete text your application displays. Read Subsetting for the character set, the policies, and the measured sizes.

Source and subset character grids for Inter, with WOFF sizes measured in the same format.

The illustrated subset uses the text above and default options. The exact size depends on the source font and the selected characters.

Choose a task

I want to... Guide
Understand families, faces, files, and glyphs Fonts
Read a font's family, style, or license fields Metadata
Check whether a font contains my characters Getting started
Load a file or bytes and read the face Reading files
Convert glyph names to Unicode text Glyph names
Write a font as TTF, WOFF, or WOFF2 Writing files
Serve a font to browsers as WOFF2 Compression
Reduce a font to the text I use Subsetting
Find a font by family, weight, and style Finding fonts
Inspect variable-font axes and glyph measurements Variable fonts
Check supported containers and outline formats Formats

The documentation index lists every main guide.

Supported fonts

ALTO Font works on TrueType outlines in TTF, OpenType, WOFF, and WOFF2 files, and on individual faces of TTC and OTC collections. Variable fonts keep their axes through conversion and subsetting. Text shaping and rendering stay with the application or browser that uses the output; Formats details each container.

Contributing

Contributions of all kinds are welcome. Visit the project on GitHub to report a bug, suggest a feature, or open a pull request.

Before submitting code, run:

# Runs PHP CS Fixer, PHPStan, and PHPUnit
composer qa

Changes to public behavior should include tests and documentation.

Support

ALTO Font is open source and independently maintained by Simon André. If it is useful to your work, you can support its continued development through GitHub Sponsors.

Sharing the package or starring it on GitHub also helps.

License

ALTO Font is released by ALTO PHP under the MIT License.