PHP | Gmagick queryfontmetrics() Function
Last Updated :
21 Jan, 2020
The Gmagick::queryfontmetrics() function is an inbuilt function in PHP which returns an array that represents the font metrics containing the characterWidth, characterHeight, ascender, descender, textWidth, textHeight and maximumHorizontalAdvance.
Syntax:
Gmagick Gmagick::queryfontmetrics( GmagickDraw $draw, string $text )
Parameters: This function accepts two parameters as mentioned above and described below:
- $draw: It specifies the GmagickDraw object.
- $text: It specifies the text.
Return Value: This function returns array containing metrics on success.
Exceptions: This function throws GmagickException on error.
Below given programs illustrate the Gmagick::queryfontmetrics() function in PHP:
Used Image:
Program 1 (See the default font metrics):
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$draw = new GmagickDraw();
$fontMetrics = $gmagick ->queryfontmetrics( $draw , 'Hello' );
print ( "<pre>" . print_r( $fontMetrics , true) . "</pre>" );
?>
|
Output:
Array
(
[characterWidth] => 12
[characterHeight] => 12
[ascender] => 12
[descender] => -4
[textWidth] => 29
[textHeight] => 15
[maximumHorizontalAdvance] => 13
)
Program 2 (See the local font file metrics):
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$draw = new GmagickDraw();
$draw ->setfont( 'Pacifico.ttf' );
$fontMetrics = $gmagick ->queryfontmetrics( $draw , 'Hello' );
print ( "<pre>" . print_r( $fontMetrics , true) . "</pre>" );
?>
|
Output:
Array
(
[characterWidth] => 12
[characterHeight] => 12
[ascender] => 17
[descender] => -6
[textWidth] => 28
[textHeight] => 22
[maximumHorizontalAdvance] => 19
)
Reference: https://www.php.net/manual/en/gmagick.queryfontmetrics.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...