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:
php
Output:
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.
<?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"));
?>
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