PHP | imageloadfont() Function
Last Updated :
14 Feb, 2020
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
$im = imagecreatetruecolor(105, 15);
$black = imagecolorallocate( $im , 0, 0, 0);
$white = imagecolorallocate( $im , 255, 255, 255);
imagefilledrectangle( $im , 0, 0, 700, 250, $white );
$font = imageloadfont( './Hollow_8x16_LE.gdf' );
imagestring( $im , $font , 0, 0, 'GeeksforGeeks' , $black );
$im1 = imagescale( $im , 700);
header( 'Content-type: image/png' );
imagepng( $im1 );
imagedestroy( $im );
?>
|
Output:
Program 2 (Writing on an image):
<?php
$im = imagecreatefrompng(
$red = imagecolorallocate( $im , 255, 0, 0);
$font = imageloadfont( './Hollow_8x16_LE.gdf' );
imagestring( $im , $font , 200, 100, 'GeeksforGeeks' , $red );
header( 'Content-type: image/png' );
imagepng( $im );
imagedestroy( $im );
?>
|
Output:
Reference: https://www.php.net/manual/en/function.imageloadfont.php
Share your thoughts in the comments
Please Login to comment...