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 'GeeksforGeeks' $font = imageloadfont( './Hollow_8x16_LE.gdf' );
imagestring( $im , $font , 0, 0, 'GeeksforGeeks' , $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 'GeeksforGeeks' $font = imageloadfont( './Hollow_8x16_LE.gdf' );
imagestring( $im , $font , 200, 100, 'GeeksforGeeks' , $red );
// Output to browser header( 'Content-type: image/png' );
imagepng( $im );
imagedestroy( $im );
?> |
Output:
Reference: https://www.php.net/manual/en/function.imageloadfont.php