Open In App

PHP | Gmagick queryfonts() Function

Improve
Improve
Like Article
Like
Save
Share
Report

The Gmagick::queryfonts() function is an inbuilt function in PHP which is used to get the configured fonts.

Syntax:

array Gmagick::queryfonts( string $pattern )

Parameters: This function accepts a single parameter $pattern which holds the regex to get the fonts, use ‘*’ to get all the fonts.

Return Value: This function returns an array value containing the fonts.

Exceptions: This function throws GmagickException on error.

Below given programs illustrate the Gmagick::queryfonts() function in PHP:

Program 1 (Getting all the available fonts):




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick();
  
// Get all the fonts
$fonts = $gmagick->queryfonts('*');
foreach ($fonts as $font) {
    echo $font . "<br>";
}
?>


Output:

AvantGarde-Book
AvantGarde-BookOblique
AvantGarde-Demi
AvantGarde-DemiOblique
Bookman-Demi
Bookman-DemiItalic
Bookman-Light
Bookman-LightItalic
Courier
Courier-Bold
Courier-Oblique
Courier-BoldOblique
Helvetica
Helvetica-Bold
Helvetica-Oblique
Helvetica-BoldOblique
Helvetica-Narrow
Helvetica-Narrow-Oblique
Helvetica-Narrow-Bold
Helvetica-Narrow-BoldOblique
NewCenturySchlbk-Roman
NewCenturySchlbk-Italic
NewCenturySchlbk-Bold
NewCenturySchlbk-BoldItalic
Palatino-Roman
Palatino-Italic
Palatino-Bold
Palatino-BoldItalic
Times-Roman
Times-Bold
Times-Italic
Times-BoldItalic
Symbol

Program 2 (Getting specific fonts):




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick();
  
// Get fonts with names starting from Times
$fonts = $gmagick->queryfonts('Times*');
  
foreach ($fonts as $font) {
    echo $font . "<br>";
}
?>


Output:

Times-Roman
Times-Bold
Times-Italic
Times-BoldItalic

Reference: https://www.php.net/manual/en/gmagick.queryfonts.php



Last Updated : 14 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads