Skip to content
Related Articles

Related Articles

Improve Article

PHP | GmagickDraw setfont() function

  • Last Updated : 23 Jan, 2020

The GmagickDraw::setfont() function is an inbuilt function in PHP which is used to set the fully-specified font to use when annotating with text.


GmagickDraw GmagickDraw::setfont( string $font )

Parameters:This function accepts a single parameter $font which is used to hold the value of font name as string.

Return Value: This function returns GmagickDraw object on success.

Exceptions: This function throws GmagickDrawException on error.

Below given programs illustrate the GmagickDraw::setfont() function in PHP:
Program 1:

// Create a GmagickDraw object
$draw = new GmagickDraw();
// Set the font using a local ttf file
// Get the font
$font = $draw->getfont();
echo $font;



Program 2:

// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
// Create a GmagickDraw object
$draw = new GmagickDraw();
// Draw rectangle for background
$draw->rectangle(-100, -1000, 800, 400);
// Set the font size
// Set the stroke color
// Set the font
// Create a rectangle
$draw->annotate(20, 110, 'GeeksforGeeks');
// Use of drawimage function
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();



My Personal Notes arrow_drop_up
Recommended Articles
Page :