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

3 COMMENTS

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS