The Imagick::setFont() function is an inbuilt function in PHP which is used to set the font.
Syntax:
bool Imagick::setFont( string $font )
Parameters: This function accepts single parameter $font which holds the name of font file.
Return Value: This function returns TRUE on success.
Extensions: GD extension needs to be installed for this function.
Below programs illustrate the Imagick::getFont() function in PHP:
Program 1:
<?php // Create a new imagick object $imagick = new Imagick(); // Use setFont() function to set the // font using .ttf font file. The .ttf // file is placed in same folder $imagick ->setFont( 'Windsong.ttf' ); // Write a caption in image format $imagick ->newPseudoImage(800, 350, "caption:GeekforGeeks" ); // Show the output $imagick ->setformat( 'png' ); header( "Content-Type: image/png" ); echo $imagick ->getImageBlob(); ?> |
Output:
Program 2:
<?php // Create a new imagick object $imagick = new Imagick(); // Set the font - make sure .ttf font file // is placed in same folder $imagick ->setFont( 'FFF_Tusj.ttf' ); // Write the caption in a image $imagick ->newPseudoImage(800, 350, "caption:GeekforGeeks" ); // Show the output $imagick ->setformat( 'png' ); header( "Content-Type: image/png" ); echo $imagick ->getImageBlob(); ?> |
Output:
Reference: https://www.php.net/manual/en/imagick.setfont.php