Tuesday, June 16, 2026
HomeLanguagesPHP | Gmagick queryfonts() Function

PHP | Gmagick queryfonts() Function

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

RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS