PHPackages                             xenocrat/sfnt2woff - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. xenocrat/sfnt2woff

ActiveLibrary[File &amp; Storage](/categories/file-storage)

xenocrat/sfnt2woff
==================

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

v4.1(2mo ago)181.5k1[1 issues](https://github.com/xenocrat/sfnt2woff/issues)BSD-3-ClausePHPPHP &gt;=8.0.0

Since Nov 16Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/xenocrat/sfnt2woff)[ Packagist](https://packagist.org/packages/xenocrat/sfnt2woff)[ Docs](https://github.com/xenocrat/sfnt2woff)[ RSS](/packages/xenocrat-sfnt2woff/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)DependenciesVersions (4)Used By (0)

What is this?
-------------

[](#what-is-this)

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

Requirements
------------

[](#requirements)

- PHP 8.0+
- ZLIB extension for WOFF 1.0 export
- [Brotli extension](https://github.com/kjdev/php-ext-brotli) for WOFF 2.0 export

Limitations
-----------

[](#limitations)

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

Usage
-----

[](#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
-------

[](#methods)

### `sfnt_import`

[](#sfnt_import)

#### Description

[](#description)

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

Imports SFNT data from a TTF or OTF font source.

#### Parameters

[](#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`

[](#otfc_import)

#### Description

[](#description-1)

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

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

#### Parameters

[](#parameters-1)

- *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.

### `otfc_extract`

[](#otfc_extract)

#### Description

[](#description-2)

```
public sfnt2woff::otfc_extract(
    int $index
): void
```

Extracts SFNT data from a TrueType or OpenType font collection. After extraction, the data can be exported using `woff1_export` or `woff2_export`.

#### Parameters

[](#parameters-2)

- *index*

    The zero-based index of the font in a collection imported using `otfc_import`. The total number of fonts in the collection is returned by `get_otfc_info`.

### `woff1_export`

[](#woff1_export)

#### Description

[](#description-3)

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

Exports SFNT data in WOFF 1.0 format.

#### Parameters

[](#parameters-3)

- *compression\_level*

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

#### Return Values

[](#return-values)

Returns a complete WOFF 1.0 file as a string of data, or `false` if there is no data to export.

### `woff2_export`

[](#woff2_export)

#### Description

[](#description-4)

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

Exports SFNT data in WOFF 2.0 format.

#### Parameters

[](#parameters-4)

- *compression\_level*

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

#### Return Values

[](#return-values-1)

Returns a complete WOFF 2.0 file as a string of data, or `false` if there is no data to export.

### `woffc_export`

[](#woffc_export)

#### Description

[](#description-5)

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

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

#### Parameters

[](#parameters-5)

- *compression\_level*

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

#### Return Values

[](#return-values-2)

Returns a complete WOFF 2.0 collection file as a string of data, or `false` if there is no data to export.

### `set_woff_version`

[](#set_woff_version)

#### Description

[](#description-6)

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

Set the major and minor version numbers for WOFF exports.

#### Parameters

[](#parameters-6)

- *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`

[](#get_woff_version)

#### Description

[](#description-7)

```
public sfnt2woff::get_woff_version(
): array
```

Get the major and minor version numbers for WOFF exports.

#### Return Values

[](#return-values-3)

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

### `set_woff_meta`

[](#set_woff_meta)

#### Description

[](#description-8)

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

Set the WOFF extended metadata block.

#### Parameters

[](#parameters-7)

- *object*

    A SimpleXMLElement object representing the XML metadata.

### `get_woff_meta`

[](#get_woff_meta)

#### Description

[](#description-9)

```
public sfnt2woff::get_woff_meta(
): object|false
```

Get the WOFF extended metadata block.

#### Return Values

[](#return-values-4)

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

### `set_woff_priv`

[](#set_woff_priv)

#### Description

[](#description-10)

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

Set the WOFF private data block.

#### Parameters

[](#parameters-8)

- *data*

    A string of data representing the private data block.

### `get_woff_priv`

[](#get_woff_priv)

#### Description

[](#description-11)

```
public sfnt2woff::get_woff_priv(
): string|false
```

Get the WOFF private data block.

#### Return Values

[](#return-values-5)

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

### `get_sfnt_info`

[](#get_sfnt_info)

#### Description

[](#description-12)

```
public sfnt2woff::get_sfnt_info(
): array|false
```

Returns information about SFNT data imported using `sfnt_import` or `otfc_extract`.

#### Return Values

[](#return-values-6)

Returns an associative array, or `false` if no data has been imported.

### `get_otfc_info`

[](#get_otfc_info)

#### Description

[](#description-13)

```
public sfnt2woff::get_otfc_info(
): array|false
```

Returns information about TTC or OTC data imported using `otfc_import`.

#### Return Values

[](#return-values-7)

Returns an associative array, or `false` if no data has been imported.

###  Health Score

44

—

FairBetter than 91% of packages

Maintenance84

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~255 days

Total

3

Last Release

76d ago

Major Versions

v3.5 → v4.02026-03-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/c9d2035a44ea3176baea09899db3766780c61dbb1238d7a2de681f6315b903ba?d=identicon)[xenocrat](/maintainers/xenocrat)

---

Top Contributors

[![xenocrat](https://avatars.githubusercontent.com/u/4855211?v=4)](https://github.com/xenocrat "xenocrat (87 commits)")

---

Tags

converterfontotfphpttfwoffwoff2converterfontttfotfwoff

### Embed Badge

![Health badge](/badges/xenocrat-sfnt2woff/health.svg)

```
[![Health](https://phpackages.com/badges/xenocrat-sfnt2woff/health.svg)](https://phpackages.com/packages/xenocrat-sfnt2woff)
```

###  Alternatives

[tecnickcom/tc-lib-pdf-font

PHP library containing PDF page formats and definitions

21845.5k15](/packages/tecnickcom-tc-lib-pdf-font)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
