PHP | Imagick queryFontMetrics() Function

The Imagick::queryFontMetrics() function is an inbuilt function in PHP which is used to return an array representing the font metrics. It takes the font and the text as parameters and return a multi-dimensional array representing the font metrics.

Syntax:

array Imagick::queryFontMetrics( $properties, $text, $multiline )

Parameters: This function accepts three parameters as mentioned above and described below:



  • $properties: This parameter holds the font properties.
  • $text: This parameter holds the text content.
  • $multiline: It holds the multiline parameter. If it left empty then it is auto detected.

Return Value: It returns a multi-dimensional array representing the font metrics.

Below program illustrates the Imagick::queryFontMetrics() function in PHP:

Program: This example returns the font properties of the text content “GeeksForGeeks”.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
/* Create a new Imagick object */
$im = new Imagick();
  
/* Create an ImagickDraw object */
$draw = new ImagickDraw();
  
/* Set the font */
$draw->setFillColor( new ImagickPixel('grey') );
  
// Top left will be point of reference
$draw->setGravity( Imagick::GRAVITY_NORTHWEST );
  
/* Dump the font metrics, autodetect multiline */
var_dump($im->queryFontMetrics($draw, "GeeksForGeeks"));
  
?>

chevron_right


Output:

array(10) { 
    ["characterWidth"]=> float(12) 
    ["characterHeight"]=> float(12) 
    ["ascender"]=> float(9) 
    ["descender"]=> float(-3) 
    ["textWidth"]=> float(88)  
    ["textHeight"]=> float(15) 
    ["maxHorizontalAdvance"]=> float(13) 
    ["boundingBox"]=> array(4) { 
        ["x1"]=> float(0.40625) 
        ["y1"]=> float(-0.046875) 
        ["x2"]=> float(5.515625) 
        ["y2"]=> float(7) 
    } 
    ["originX"]=> float(88) 
    ["originY"]=> float(0) 
}

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.