Friday, October 24, 2025
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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS