PHP code example of php-io-extensions / fontconfig

1. Go to this page and download the library: Download php-io-extensions/fontconfig library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

php-io-extensions / fontconfig example snippets


$config = FcInitLoadConfigAndFonts();
$pattern = FcNameParse('monospace');
FcConfigSubstitute($config, $pattern, FcMatchPattern);
FcDefaultSubstitute($pattern);

$match = FcFontMatch($config, $pattern, $result);
FcPatternGetString($match, FC_FAMILY, 0, $family);
FcPatternGetString($match, FC_STYLE, 0, $style);
FcPatternGetString($match, FC_FILE, 0, $file);
FcPatternGetInteger($match, FC_INDEX, 0, $index);
echo "{$family} {$style}: {$file} #{$index}\n";

$set = FcFontSort($config, $pattern, true, $coverage, $result);
foreach ($set->fonts as $font) {
    FcPatternGetCharSet($font, FC_CHARSET, 0, $charset);
    if (FcCharSetHasChar($charset, 0x4E2D)) {
        FcPatternGetString($font, FC_FILE, 0, $fallback);
        echo "中: {$fallback}\n";
        break;
    }
}

FcCharSetDestroy($coverage);
FcFontSetDestroy($set);
FcPatternDestroy($match);
FcPatternDestroy($pattern);
FcConfigDestroy($config);
console
$ php match.php
Andale Mono Regular: /System/Library/Fonts/Supplemental/Andale Mono.ttf #0
中: /System/Library/Fonts/ヒラギノ丸ゴ ProN W4.ttc
bash
git clone https://github.com/php-io-extensions/fontconfig.git
cd fontconfig

./install-debian-trixie.sh             # Debian Trixie, Ubuntu 24.04+, Raspberry Pi OS: the php on PATH
./install-macos.sh                     # Homebrew [email protected] and [email protected]
./install-macos.sh /path/to/bin/php    # the macOS script takes specific PHP binaries
bash
git clone https://github.com/php-io-extensions/fontconfig.git
cd fontconfig
phpize && ./configure --enable-fontconfig && make -j"$(nproc 2>/dev/null || sysctl -n hw.ncpu)"
composer install
mkdir -p /tmp/fontconfig-ini && echo "extension=$PWD/modules/fontconfig.so" > /tmp/fontconfig-ini/fontconfig.ini
PHP_INI_SCAN_DIR=":/tmp/fontconfig-ini" php -d memory_limit=128M vendor/bin/pest