PHPackages                             php-sdl/sdl3-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. php-sdl/sdl3-ttf

ActivePhp-ext[Utility &amp; Helpers](/categories/utility)

php-sdl/sdl3-ttf
================

PHP extension for SDL3\_ttf — TrueType font rendering built with Zephir

v0.2.0(1mo ago)02MITCPHP &gt;=8.2CI passing

Since Apr 16Pushed 1mo agoCompare

[ Source](https://github.com/php-sdl/sdl3-ttl)[ Packagist](https://packagist.org/packages/php-sdl/sdl3-ttf)[ RSS](/packages/php-sdl-sdl3-ttf/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (2)Used By (0)

php-sdl3-ttf
============

[](#php-sdl3-ttf)

[![CI](https://github.com/php-sdl/sdl3-ttl/actions/workflows/ci.yml/badge.svg)](https://github.com/php-sdl/sdl3-ttl/actions/workflows/ci.yml)[![PHP](https://camo.githubusercontent.com/c43902a50e55ff766fc179e27d9b9a292ef8fcadbdd4d855bb077a334e2f9b46/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d254532253839254135253230382e322d3737376262343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://www.php.net)[![SDL3](https://camo.githubusercontent.com/0d60227c13873647c269a604bb58bab7866996600408cd565817dcc32b4e3cd0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53444c332d254532253839254135253230332e342e302d316434656438)](https://www.libsdl.org/)[![SDL3_ttf](https://camo.githubusercontent.com/5bf2bf6808f80df5614bd86769447fa73e7cd5106315d5a5436783947d7daf12/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53444c335f5f7474662d254532253839254135253230332e322d316434656438)](https://github.com/libsdl-org/SDL_ttf)[![Built with Zephir](https://camo.githubusercontent.com/8e72a9e9874ec036e66f84af12bd028857d1f200674b7acaa9eb97271a123f7c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c74253230776974682d5a65706869722d666636613030)](https://zephir-lang.com/)[![Platform](https://camo.githubusercontent.com/37c663164df6eec24d0327668403be1782ab3245cf57963be37d9b6873a823a8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f706c6174666f726d2d6c696e75782532302537432532306d61634f532d6c6967687467726579)](#requirements)[![License: MIT](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](#license)

> PHP extension for SDL3\_ttf — TrueType font rendering built with [Zephir](https://zephir-lang.com/).

`sdl3ttf` wraps [SDL3\_ttf](https://github.com/libsdl-org/SDL_ttf) for PHP 8.2+, giving you hardware-quality TrueType and OpenType font rendering from plain PHP scripts. It links against the system `libSDL3` and `libSDL3_ttf`, so glyph rasterisation is as fast as a native C program.

Pair it with [php-sdl/sdl3](https://github.com/php-sdl/sdl3) for windowing, rendering, and event handling — both extensions share the `Sdl3*` top-level namespace and can be loaded side-by-side.

---

Table of contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
    - [Via PHP PIE (recommended)](#via-php-pie-recommended)
    - [Platform installers](#platform-installers)
    - [Manual build with `phpize`](#manual-build-with-phpize)
- [Verifying the install](#verifying-the-install)
- [Quick start](#quick-start)
- [API reference](#api-reference)
- [License](#license)

---

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

[](#requirements)

ComponentMinimum versionNotesPHP8.2ZTS and NTS builds both supported.[php-sdl/sdl3](https://github.com/php-sdl/sdl3)any**Required.** Provides the SDL3 window, renderer, and surface types this extension works with.SDL33.4.0C library — must be discoverable via `pkg-config sdl3`.SDL3\_ttf3.2C library — must be discoverable via `pkg-config SDL3_ttf` (or `sdl3-ttf` / `sdl3_ttf`).OSLinux / macOSWindows is not currently supported.CompilerC11 toolchain`gcc`, `clang`, or Apple Clang.`php-dev` / `phpize`matches PHPRequired for any build path.Tested on macOS (Apple Silicon + Intel), Debian Trixie, Raspberry Pi OS (arm64 / armhf), and NVIDIA JetPack 6 (Jetson Orin).

---

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

[](#installation)

### Via PHP PIE (recommended)

[](#via-php-pie-recommended)

Install [php-sdl/sdl3](https://github.com/php-sdl/sdl3) first (required), then install this extension:

```
pie install php-sdl/sdl3
pie install php-sdl/sdl3-ttf
```

PIE handles the full build pipeline (phpize → configure → make → install) automatically. Make sure SDL3 ≥ 3.4.0 and SDL3\_ttf ≥ 3.2 are already installed on the system before running — use the platform scripts below if they are not.

### Platform installers

[](#platform-installers)

Three installer scripts live at the repository root. Each one installs SDL3 and SDL3\_ttf if they are missing, builds the extension with Zephir, and enables it for every detected PHP SAPI.

**macOS** (Homebrew):

```
bash install-macos.sh
```

**Debian Trixie / Raspberry Pi OS** (amd64, arm64, armhf):

```
bash install-debian-trixie.sh
```

**JetPack 6 / Ubuntu 22.04** (builds SDL3 + SDL3\_ttf from source):

```
bash install-jetpack6.sh
```

Each script writes a full build log to `./build.log` and prints concise failure diagnostics if anything goes wrong.

### Manual build with `phpize`

[](#manual-build-with-phpize)

If the generated C source exists in `ext/`, you can build without Zephir:

```
cd ext
phpize
./configure --enable-sdl3ttf
make -j"$(nproc 2>/dev/null || sysctl -n hw.logicalcpu)"
sudo make install
```

Then enable the extension:

```
; /etc/php/8.4/cli/conf.d/30-sdl3ttf.ini
extension=sdl3ttf.so
```

If SDL3 or SDL3\_ttf is installed in a non-standard prefix, export `PKG_CONFIG_PATH=/usr/local/lib/pkgconfig` before `./configure`.

---

Verifying the install
---------------------

[](#verifying-the-install)

Run the bundled proof-of-work script — it opens a system font, renders text to a surface, and reports dimensions. No display server required.

```
php examples/proof_of_work.php
```

Expected output:

```
✓  Extension 'sdl3ttf' is loaded
✓  Font: /System/Library/Fonts/Supplemental/Arial.ttf
✓  TTF_Init() → ok
✓  TTFOpenFont() → ptr=0x…
     height=27  ascent=22  descent=-5  line_skip=28  fixed=no
✓  TTFRenderTextBlended()
     surface ptr=0x…  size=263x27  pitch=1104
     pixels in data array: 7101  (expected 7101)
✓  Pixel data matches surface dimensions
     mid-row preview: [ ███ ░ ██░   ░  ░░ █  …  ]
✓  TTFCloseFont()
✓  TTFQuit()

✅  All checks passed — sdl3ttf is working correctly.

```

A one-liner sanity check:

```
php -m | grep sdl3ttf
```

---

Quick start
-----------

[](#quick-start)

```
