Open In App

PHP | Imagick queryFontMetrics() Function

Last Updated : 11 Jul, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
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". php
<?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"));

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

Next Article

Similar Reads