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):

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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>";
}
?>

chevron_right


Output:

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

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

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.