xenocrat/sfnt2woff

A PHP class for converting OTF/TTF files to WOFF.

Maintainers

Package info

github.com/xenocrat/sfnt2woff

pkg:composer/xenocrat/sfnt2woff

Statistics

Installs: 1 450

Dependents: 0

Suggesters: 0

Stars: 18

Open Issues: 1

v4.0 2026-03-27 08:41 UTC

This package is auto-updated.

Last update: 2026-04-05 09:58:26 UTC


README

sfnt2woff is a PHP class for converting OTF, TTF, and TTC files to WOFF 1.0 and 2.0.

Requirements

  • PHP 8.0+
  • ZLIB extension for WOFF 1.0 export
  • Brotli extension for WOFF 2.0 export

Limitations

WOFF 2.0 export uses a null transformation: table data is not optimized.

Usage

Convert a font to WOFF 1.0:

$sfnt2woff = new \xenocrat\sfnt2woff();
$sfnt = file_get_contents("font.ttf");
$sfnt2woff->sfnt_import($sfnt);
$woff = $sfnt2woff->woff1_export();
file_put_contents("font.woff", $woff);

Convert a font to WOFF 2.0:

$sfnt2woff = new \xenocrat\sfnt2woff();
$sfnt = file_get_contents("font.ttf");
$sfnt2woff->sfnt_import($sfnt);
$woff = $sfnt2woff->woff2_export();
file_put_contents("font.woff2", $woff);

Methods

sfnt_import

Description

public sfnt2woff::sfnt_import(
    string $sfnt,
    bool $verify_checksums = true
): void

Imports SFNT data from a TTF or OTF font source.

Parameters

  • sfnt

    A complete TTF or OTF file as a string of data.

  • verify_checksums

    Whether or not to verify the table data checksums on import.

otfc_import

Description

public sfnt2woff::otfc_import(
    string $otfc,
    bool $verify_checksums = true
): void

Imports TTC or OTC data from a TrueType or OpenType font collection.

Parameters

  • otfc

    A complete TTC or OTC file as a string of data.

  • verify_checksums

    Whether or not to verify the table data checksums on import.

woff1_export

Description

public sfnt2woff::woff1_export(
    int $compression_level = -1
): string

Exports SFNT data in WOFF 1.0 format.

Parameters

  • compression_level

    The compression level, from 0 (minimum) to 9 (maximum).

Return Values

Returns a complete WOFF 1.0 file as a string of data.

woff2_export

Description

public sfnt2woff::woff2_export(
    int $compression_level = -1
): string

Exports SFNT data in WOFF 2.0 format.

Parameters

  • compression_level

    The compression level, from 0 (minimum) to 11 (maximum).

Return Values

Returns a complete WOFF 2.0 file as a string of data.

woffc_export

Description

public sfnt2woff::woffc_export(
    int $compression_level = -1
): string

Exports TTC or OTC data in WOFF 2.0 font collection format.

Parameters

  • compression_level

    The compression level, from 0 (minimum) to 11 (maximum).

Return Values

Returns a complete WOFF 2.0 file as a string of data.

set_woff_version

Description

public sfnt2woff::set_woff_version(
    int $major,
    int $major
): void

Set the major and minor version numbers for WOFF exports.

Parameters

  • major

    The major version, an integer in the range 0-65535.

  • minor

    The minor version, an integer in the range 0-65535.

get_woff_version

Description

public sfnt2woff::get_woff_version(
): array

Get the major and minor version numbers for WOFF exports.

Return Values

Returns an array of two integers representing the major and minor version numbers.

set_woff_meta

Description

public sfnt2woff::set_woff_meta(
    SimpleXMLElement $object
): void

Set the WOFF extended metadata block.

Parameters

  • object

    A SimpleXMLElement object representing the XML metadata.

get_woff_meta

Description

public sfnt2woff::get_woff_meta(
): object|false

Get the WOFF extended metadata block.

Return Values

Returns a SimpleXMLElement object representing the XML metadata, or false if no metadata block has been set.

set_woff_priv

Description

public sfnt2woff::set_woff_priv(
    string $data
): void

Set the WOFF private data block.

Parameters

  • data

    A string of data representing the private data block.

get_woff_priv

Description

public sfnt2woff::get_woff_priv(
): string|false

Get the WOFF private data block.

Return Values

Returns a string of data representing the private data block, or false if no private data block has been set.