Friday, November 21, 2025
HomeLanguagesPHP | imageloadfont() Function

PHP | imageloadfont() Function

The imageloadfont() function is an inbuilt function in PHP which is used to load a new font. GDF fonts are supported which can be downloaded from here.

Syntax:

int imageloadfont( string $file )

Parameters: This function accepts a single parameter $file which holds the font.

Return Value: This function returns font identifier which is always bigger than 5 to avoid conflicts with built-in fonts or FALSE on errors.

Below given programs illustrate the imageloadfont() function in PHP:

Program 1 (Writing on a drawing):




<?php
  
// Create a new image instance
$im = imagecreatetruecolor(105, 15);
  
// Prepare the colors
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
  
// Make the background white
imagefilledrectangle($im, 0, 0, 700, 250, $white);
  
// Load the gd font from local folder
// and write 'neveropen'
$font = imageloadfont('./Hollow_8x16_LE.gdf');
imagestring($im, $font, 0, 0, 'neveropen', $black);
  
// Scale the image bigger
$im1 = imagescale($im, 700);
  
// Output to browser
header('Content-type: image/png');
imagepng($im1);
imagedestroy($im);
?>


Output:

Program 2 (Writing on an image):




<?php
  
// Create an image instance
$im = imagecreatefrompng(
  
// Prepare the red color
$red = imagecolorallocate($im, 255, 0, 0);
  
// Load the gd font from local folder and write 'neveropen'
$font = imageloadfont('./Hollow_8x16_LE.gdf');
imagestring($im, $font, 200, 100, 'neveropen', $red);
  
// Output to browser
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>


Output:

Reference: https://www.php.net/manual/en/function.imageloadfont.php

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6781 POSTS0 COMMENTS
Nicole Veronica
11928 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11997 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7166 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS