Friday, October 10, 2025
HomeLanguagesPHP | GmagickDraw getfont() Function

PHP | GmagickDraw getfont() Function

The GmagickDraw::getfont() function is an inbuilt function in PHP which is used to get the string specifying the font used when annotating with text.

Syntax:

string GmagickDraw::getfont( void )

Parameters: This function doesn’t accept any parameters.

Return Value: This function returns an string value containing the font.

Exceptions: This function throws GmagickDrawException on error.

Below given programs illustrate the GmagickDraw::getfont() function in PHP:

Program 1:




<?php 
  
// Create a new GmagickDraw object 
$draw = new GmagickDraw(); 
    
// Get the font 
$font = $draw->getfont(); 
echo $font
?>


Output:

Empty string which is the default font.

Used Image:

Program 2:




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('neveropen.png');
  
// Create a GmagickDraw object
$draw = new GmagickDraw();
  
// Set the color
$draw->setFillColor('#0E0E0E');
  
// Draw rectangle for background
$draw->rectangle(-10, -10, 800, 400);
  
// Set the fill color
$draw->setFillColor('yellow');
  
// Set the font size
$draw->setFontSize(20);
  
// Set the font to a ttf file which should be
// placed in same folder where the program is.
$draw->setFont('Pacifico.ttf');
  
// Annotate a text
$draw->annotate(50, 120, 'The Font here is '
    . $draw->getfont() . '.');
  
// Use of drawimage functeannotate
$gmagick->drawImage($draw);
  
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>


Output:

Reference: https://www.php.net/manual/en/gmagickdraw.getfont.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS