PHP | Imagick setFont() Function

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 funtion.

Below programs illustrate the Imagick::getFont() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
?>

chevron_right


Output:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/imagick.setfont.php



My Personal Notes arrow_drop_up

I love Open Source Culture have contributed to phpMyAdmin, LibreOffice, Ant-Design and Web is my passion

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.