(PHP 4, PHP 5, PHP 7)

imageloadfontLädt einen neuen Font


int imageloadfont ( string $file )

ImageLoadFont() lädt einen vom Benutzer definierten Bitmap-Font und gibt einen Zeiger auf diesen zurück. Dessen Wert ist immer größer als 5, um Konflikte mit den eingebauten Fonts zu vermeiden.

Das Font-Datei-Format unterliegt binären Abhängigkeiten und ist von Rechner-Typ zu Rechner-Typ unterschiedlich. Das bedeutet, dass Sie die Font-Dateien immer auf dem Rechner-Typ erzeugen müssen, auf dem diese Verwendung finden.

Byte-Position C Daten-Typ Beschreibung
Byte 0-3 int Anzahl der Zeichen des Font
Byte 4-7 int Wert des ersten Zeichens des Fonts (meist 32 für Leerzeichen)
Byte 8-11 int Pixel-Breite jedes Zeichens
Byte 12-15 int Pixel-Höhe jedes Zeichens
Byte 16- Zeichen Zeichen-Daten als Array, ein Byte je Pixel für jedes Zeichen; in der Summe also (Anzahl-Zeichen * Breite * Höhe)-Bytes.

Siehe auch imagefontwidth() und imagefontheight().

add a note add a note

User Contributed Notes 6 notes

siker at norwinter dot com
13 years ago
Working under the assumption that the only 'architecture dependant' part of the font files is endianness, I wrote a quick and dirty Python script to convert between the two. It has only been tested on a single font on a single machine so don't bet your life on it working. All it does is swap the byte order of the first four ints.

#!/usr/bin/env python

f = open("myfont.gdf", "rb");
d = open("myconvertedfont.gdf", "wb");

for i in xrange(4):
        b = [ for j in xrange(4)];


I successfully used this script to convert anonymous.gdf, from one of the font links below, into something useable on Mac OS X.
alex at bestgames dot ro
13 years ago
Confirmation code generation for preventing automated registrations on a website.

Function arguments are:
$code - the code that you shall random generate
$location - relative location of the image that shall be generated
$fonts_dir - relative location for the GDF fonts directory

This function will create an image with the code given by you and will save it in the directory specified with the name formed by MD5 hash of the code.

You may insert as many font types in the fonts directory as you wish, with random names.

function generate_image($code, $location, $fonts_dir)
$image  = imagecreate(150, 60);          
imagecolorallocate($image, rand(0, 100), rand(100, 150), rand(150, 250));
$fonts = scandir($fonts_dir);
$max = count($fonts) - 2;
$width = 10;
     for (
$i = 0; $i <= strlen($code); $i++)
$textcolor = imagecolorallocate($image, 255, 255, 255);
$rand = rand(2, $max);
$font = imageloadfont($fonts_dir."/".$fonts[$rand]);
$fh = imagefontheight($font);
$fw = imagefontwidth($font);

imagechar($image, $font, $width, rand(10, 50 - $fh), $code[$i], $textcolor);    
$width = $width + $fw;
imagejpeg($image, $location."/".md5($code).".jpg", 100);

puremango dot co dot uk at gmail dot com
13 years ago
I've written an online tool in PHP that allows you to create GD fonts from PNG images.

much usefulness for custom font creation, I feel.

see the tool@
(source available online)
angryziber at mail dot com
18 years ago
You all should look at the GD image library site for information on extra fonts, it can be found at
matthew at exanimo dot com
13 years ago
Remember - GD fonts aren't antialiased.  If you're planning on using a pre-existing (TrueType) font, you may want to consider using imagettftext() instead of phillip's function.
widget at oneblacksheep dot com
14 years ago
After noting the gd fonts page from dryes58 above was down I contacted the him and have put the pages up at hows about that then =)
To Top