1. Products
  2.   Font
  3.   PHP
  4.   PHP Font Lib
 
  

Free PHP Library to Read, Parse & Export Fonts

Open Source PHP API to Load, Read, Parse, Export and Generate subsets of different types of font files and Extract meta data, horizontal metrics & textual info.

PHP Font Lib is a powerful open source PHP library that provides software developers with a comprehensive set of tools for working with various types of fonts. Whether developers need to manipulate font files, extract metadata, or generate dynamic text, this versatile library has got it covered. Developed by a community of font enthusiasts, it is a reliable and extensively documented tool that can be easily integrated into your PHP projects. Software developers can dynamically manipulate fonts, enabling the creation of visually appealing typography effects on-the-fly using the PHP Font Lib.

PHP Font Lib is an open source library designed to handle various aspects of font manipulation in PHP applications with just a couple of lines of code, such as extracting metadata, font parsing, glyph manipulation, creating font subsets, creation of AdobeFontMetrics (AFM) files, convert font formats, extraction glyph data or even generate custom fonts. The ability to manipulate glyphs empowers developers to create personalized fonts tailored to specific branding or design requirements. Customized fonts can enhance the uniqueness and recognizability of web applications or printed materials.

Whether you need to parse, manipulate, or generate fonts, this versatile library offers a comprehensive set of tools and functionalities. Developed by the talented team at PHP Font Lib, this library provides a comprehensive set of functionalities for working with various types of fonts, such as TrueType, OpenType, Type1 font files, and many more. Its flexibility and versatility make it a valuable asset for web developers, designers, and anyone involved in font-related tasks. Embrace the potential of PHP Font Lib and take your font-related endeavors to the next level.

Previous Next

Getting Started with PHP Font Lib

PHP Font Lib requires PHP version 5.2 or newer. The recommended way to install PHP Font Lib is using Composer. Please use the following command a smooth installation.

Install PHP Font Lib via Composer

 composer require phenx/php-font-lib

You can also install it manually; download the latest release files directly from GitHub repository.

Load & Extract Font Information via PHP API

The open source PHP Font Lib library gives software developers the capability to load various types of fonts (TrueType, OpenType and WOFF) and extract information about these fonts inside their own PHP applications. The library allows Software developers to extract detailed information from font files, such as font names, metrics, style, supported character sets, and more. This feature enables dynamic font management and retrieval of essential font data. The following example shows how software developers can load various font information using PHP code.

Load & Display Various Font Information using PHP API

$font = \FontLib\Font::load('fontfile.ttf');
$font->parse();  // for getFontWeight() to work this call must be done first!
echo $font->getFontName() .'
'; echo $font->getFontSubfamily() .'
'; echo $font->getFontSubfamilyID() .'
'; echo $font->getFontFullName() .'
'; echo $font->getFontVersion() .'
'; echo $font->getFontWeight() .'
'; echo $font->getFontPostscriptName() .'
'; $font->close();

Create & Manage Font Subset via PHP

The PHP Font Lib library has included support for a very useful feature for generating and managing font subsets inside their PHP applications with ease. This feature allows software professionals to extract only the characters needed for a particular application, reducing file size and optimizing performance. The following example demonstrates how software developers can create Font subset with just couple of lines of PHP code inside PHP applications.

How to Create Font Subsetusing PHP API?

$font = FontLib\Font::load('fontfile.ttf');
$font->parse();
$font->setSubset("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ.:,;' (!?)+-*/== 1234567890"); // characters to include
$font->reduce();
touch('fontfile.subset.ttf');
$font->open('fontfile.subset.ttf', FontLib\BinaryStream::modeReadWrite);
$font->encode(array("OS/2"));
$font->close();

Glyph Manipulation Support in PHP Apps

The open source PHP Font Lib library has included support for working with font glyph data using PHP commands. It enables software developers to work with individual glyphs within a font file. Moreover, software developers can access glyph properties like coordinates, outlines, and bounding boxes, allowing them to perform advanced operations such as glyph substitution, scaling, and rotation. This feature is particularly useful for creating custom font effects or generating dynamic text.