HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

imageloadfont

Description

The imageloadfont of Image for PHP load a new font.

Syntax

imageloadfont(
    string $filename
): GdFont|false

Parameters

filename

The font file format is currently binary and architecture dependent. This means you should generate the font files on the same type of CPU as the machine you are running PHP on.

Byte PositionTypeDescription
byte 0-3intnumber of characters in the font
byte 4-7intvalue of first character in the font (often 32 for space)
byte 8-11intpixel width of each character
byte 12-15intpixel height of each character
byte 16-chararray with character data, one byte per pixel in each character, for a total of (nchars*width*height) bytes.

Return

Returns an GdFont instance, or false on failure.

Examples

1 · return

<?

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/gdf/1.gdf';

$return = imageloadfont($filename);

var_dump($return);
object(GdFont)#1 (0) {
}

2 · base64

<?

$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);

$red = 255;
$green = 255;
$blue = 255;
$color = imagecolorallocate($image, $red, $green, $blue);

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/gdf/1.gdf';
$font = imageloadfont($filename);

$x = 0;
$y = 0;
$string = "string";
imagestring($image, $font, $x, $y, $string, $color);

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/gdf/2.gdf';
$font = imageloadfont($filename);

$x = 0;
$y = 20;
$string = "string";
imagestring($image, $font, $x, $y, $string, $color);

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/gdf/3.gdf';
$font = imageloadfont($filename);

$x = 0;
$y = 40;
$string = "string";
imagestring($image, $font, $x, $y, $string, $color);

ob_start();

    imagepng($image);

$output = ob_get_clean();

echo '<!doctype html>
<html>
<body>
    <img src="data:image/png;base64,' . base64_encode($output) . '">
</body>
</html>';
<!doctype html>
<html>
<body>
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB0ElEQVR4nO3b27KDIAxAUXD8/1+mD14GAUNwVILd66kHqaPhcpBY53CjEELvS7Bikg9fiFQI4avxrQQLsfn2M3rvbz+nEd6Vxtpyw0l5XOi9j4/uAdoLk5K4fl45P49N09n8Is87rbNSXH/5POK8tg7DvEmTfpR/86zwLApCb83LbVqDVRxTgtbxYnx8KU3fuI13zO7Y7MsqiQgWzZrJIv9HVq2pjPgQU9WusCiNb/K5LkbnvW6Ih6T7V/B69qOTMPRsyMAEAACoGW61qVRflH71zh/xWrDst4q0UxrvtyTlxQREsbJcX7/5Y0XSpPKfLtshKFbQ1JdPYlBlP+vMn+7Buy0lc7ltvxEIjUMqTEh8PUGY+Gw6bP7tIXvz0ocI02JyvSfXsOl4DUprKkxIsu5Hm7I1mq8kXZgUnKS6RrGmc0u2vjYAAACAP3ThqW2UB70LDL1FYx+/sGhAz2pQfmdf84J/cetGTuE0HTKosptcPBRH5CxeZyWaz2YxDBtcn+CXXmC8L9xrTYW5ofbCe1mHod+4EbZ3e+k5Z8U9uuNl6PX80YAb8feGwmInzuy3psL+au5/XDwAhxiMpMIAAAAAAAAAAAAAAAAAAAAAAAB+sNlTHLs39T4AAAAASUVORK5CYII=">
</body>
</html>