PHPackages                             serafim/ffi-sdl-ttf - 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. serafim/ffi-sdl-ttf

ActiveLibrary

serafim/ffi-sdl-ttf
===================

SDL TTF FFI bindings for the PHP language

2.0.3(1y ago)22372[1 issues](https://github.com/SerafimArts/ffi-sdl-ttf/issues)MITCPHP ^8.1CI passing

Since Apr 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/SerafimArts/ffi-sdl-ttf)[ Packagist](https://packagist.org/packages/serafim/ffi-sdl-ttf)[ Docs](https://github.com/SerafimArts/ffi-sdl-ttf)[ RSS](/packages/serafim-ffi-sdl-ttf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (14)Versions (7)Used By (0)

FFI SDL TTF Bindings
====================

[](#ffi-sdl-ttf-bindings)

 [![PHP 8.1+](https://camo.githubusercontent.com/d1ed96ed9bbc07db695a86735dd04c2898249af67264a564bb2c9bc0dbe67774/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6666692d73646c2d7474662f726571756972652f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/serafim/ffi-sdl-ttf) [![SDL_ttf](https://camo.githubusercontent.com/7800601997f1ef91003c77bf4d8ae40ca510a71743b4c151fd9ceae0b1b1e7d4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53444c5f5454462d322e32302e322d3133324234382e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d63253262253262)](https://github.com/libsdl-org/SDL_ttf) [![Latest Stable Version](https://camo.githubusercontent.com/9ec2c2ad9c36fd3fad549785e32c76f9bc46f9743d49ac51aea9630babd280a6/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6666692d73646c2d7474662f76657273696f6e3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/serafim/ffi-sdl-ttf) [![Latest Unstable Version](https://camo.githubusercontent.com/f904792db3d9eeab48f000a39e17472d67861dde072aa571e1ab3e6253574911/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6666692d73646c2d7474662f762f756e737461626c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/serafim/ffi-sdl-ttf) [![Total Downloads](https://camo.githubusercontent.com/d966144c1c9fa4f384175ca970d95e8caf3ea05c5241d709ddfb23ff942bb845/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6666692d73646c2d7474662f646f776e6c6f6164733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/serafim/ffi-sdl-ttf) [![License MIT](https://camo.githubusercontent.com/b778d2360d42579f6f365e66ea3185d4fbf19a34778c293d6b1821ed0659ca54/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6666692d73646c2d7474662f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://raw.githubusercontent.com/serafim/ffi-sdl-ttf/master/LICENSE.md)

A SDL\_ttf extension FFI bindings for the PHP language compatible with [SDL FFI bindings for the PHP language](https://github.com/SerafimArts/ffi-sdl).

- [System Requirements](#requirements)
- [Installation](#installation)
- [Documentation](#documentation)
- [Initialization](#initialization)
- [Example](#example)

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

[](#requirements)

- PHP ^8.1
- ext-ffi
- Windows, Linux, BSD or MacOS
    - Android, iOS or something else are not supported yet
- SDL and SDL TTF &gt;= 2.0

Installation
------------

[](#installation)

Library is available as composer repository and can be installed using the following command in a root of your project.

```
$ composer require serafim/ffi-sdl-ttf
```

Additional dependencies:

- Debian-based Linux: `sudo apt install libsdl2-ttf-2.0-0 -y`
- MacOS: `brew install sdl2_ttf`
- Window: Can be [downloaded from here](https://github.com/libsdl-org/SDL_ttf/releases)

Documentation
-------------

[](#documentation)

The library API completely supports and repeats the analogue in the C language.

- [SDL2 TTF official documentation](https://www.libsdl.org/projects/SDL_ttf/docs/index.html)

Initialization
--------------

[](#initialization)

In the case that you need a specific SDL instance, it should be passed explicitly:

```
$sdl = new Serafim\SDL\SDL(version: '2.28.3');
$ttf = new Serafim\SDL\TTF\TTF(sdl: $sdl);

// If no argument is passed, the latest initialized
// version will be used.
$ttf = new Serafim\SDL\TTF\TTF(sdl: null);
```

> ! It is recommended to always specify the SDL dependency explicitly.

To specify a library pathname explicitly, you can add the `library` argument to the `Serafim\SDL\TTF\TTF` constructor.

> By default, the library will try to resolve the binary's pathname automatically.

```
// Load library from pathname (it may be relative or part of system-dependent path)
$ttf = new Serafim\SDL\TTF\TTF(library: __DIR__ . '/path/to/library.so');

// Try to automatically resolve library's pathname
$ttf = new Serafim\SDL\TTF\TTF(library: null);
```

You can also specify the library version explicitly. Depending on this version, the corresponding functions of the SDL Image will be available.

> By default, the library will try to resolve SDL Image version automatically.

```
// Use v2.0.14 from string
$ttf = new Serafim\SDL\TTF\TTF(version: '2.0.14');

// Use v2.20.2 from predefined versions constant
$ttf = new Serafim\SDL\TTF\TTF(version: \Serafim\SDL\TTF\Version::V2_20_2);

// Use latest supported version
$ttf = new Serafim\SDL\TTF\TTF(version: \Serafim\SDL\TTF\Version::LATEST);
```

To speed up the header compiler, you can use any PSR-16 compatible cache driver.

```
$ttf = new Serafim\SDL\TTF\TTF(cache: new Psr16Cache(...));
```

In addition, you can control other preprocessor directives explicitly:

```
$pre = new \FFI\Preprocessor\Preprocessor();
$pre->define('true', 'false'); // happy debugging!

$ttf = new Serafim\SDL\TTF\TTF(pre: $pre);
```

Example
-------

[](#example)

```
use Serafim\SDL\SDL;
use Serafim\SDL\TTF\TTF;

$sdl = new SDL();
$ttf = new TTF(sdl: $sdl);

$sdl->SDL_Init(SDL::SDL_INIT_EVERYTHING);
$ttf->TTF_Init();

$font = $ttf->TTF_OpenFont(__DIR__ . '/path/to/font.ttf', 42);

echo 'Hinting: ' . $ttf->TTF_GetFontHinting($font) . "\n";
echo 'Kerning: ' . $ttf->TTF_GetFontKerning($font) . "\n";
echo 'Style:   ' . match($ttf->TTF_GetFontStyle($font)) {
    TTF::TTF_STYLE_NORMAL => 'normal',
    TTF::TTF_STYLE_BOLD => 'bold',
    TTF::TTF_STYLE_ITALIC => 'italic',
    TTF::TTF_STYLE_UNDERLINE => 'underline',
    TTF::TTF_STYLE_STRIKETHROUGH => 'strikethrough',
}   . "\n";

$color = $sdl->new('SDL_Color');
$color->r = 120;
$color->g = 100;
$color->b = 80;

$surface = $ttf->TTF_RenderText_Solid($font, 'Hello World!', $color);

$ttf->TTF_Quit();
$sdl->SDL_Quit();
```

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% 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 ~339 days

Recently: every ~120 days

Total

6

Last Release

521d ago

Major Versions

1.0.0 → 2.0.0-beta12023-08-12

PHP version history (2 changes)1.0.0PHP &gt;=7.4

2.0.0-beta1PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Top Contributors

[![SerafimArts](https://avatars.githubusercontent.com/u/2461257?v=4)](https://github.com/SerafimArts "SerafimArts (6 commits)")[![he426100](https://avatars.githubusercontent.com/u/9689137?v=4)](https://github.com/he426100 "he426100 (1 commits)")

---

Tags

ffiffi-bindingsphpsdl2sdl2-ttflibrarygraphicsfontffittfbindingsopenglsdl

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/serafim-ffi-sdl-ttf/health.svg)

```
[![Health](https://phpackages.com/badges/serafim-ffi-sdl-ttf/health.svg)](https://phpackages.com/packages/serafim-ffi-sdl-ttf)
```

###  Alternatives

[serafim/ffi-sdl

SDL FFI bindings for the PHP language

324.6k3](/packages/serafim-ffi-sdl)[nutgram/nutgram

The Telegram bot library that doesn't drive you nuts

714214.9k8](/packages/nutgram-nutgram)[tecnickcom/tc-lib-pdf-font

PHP library containing PDF page formats and definitions

21773.2k5](/packages/tecnickcom-tc-lib-pdf-font)[digitalstars/simplevk

Powerful PHP library/framework for VK API bots, supporting LongPoll &amp; Callback &amp; OAuth

883.9k3](/packages/digitalstars-simplevk)[xenocrat/sfnt2woff

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

181.4k](/packages/xenocrat-sfnt2woff)

PHPackages © 2026

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