Wednesday, June 17, 2026
HomeLanguagesPHP | Imagick setFont() Function

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

RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS