Tuesday, May 26, 2026
HomeLanguagesPHP | Gmagick queryformats() Function

PHP | Gmagick queryformats() Function

The Gmagick::queryformats() function is an inbuilt function in PHP which is used to get the format supported by Gmagick object.

Syntax:

array Gmagick::queryformats( string $pattern )

Parameters: This function accepts a single parameter $pattern which holds the regex pattern to check if a format is supported or not.

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

Exceptions: This function throws GmagickException on error.

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

Program 1 (Get all the formats):




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


Output:

3FR
8BIM
8BIMTEXT
8BIMWTEXT
APP1
APP1JPEG
ART
ARW
AVS
.
.
.etc

Program 2 (Checking if a format is supported):




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick();
  
// Get all formats
$formats = $gmagick->queryformats('*');
  
// Call the checker function
checkFormat('JPEG', $formats);
checkFormat('xyz', $formats);
  
// Checker function
function checkFormat($format, $formats)
{
    if (in_array($format, $formats)) {
        echo $format . ' is supported<br>';
    } else {
        echo $format . ' isn\'t supported<br>';
    }
}
?>


Output:

JPEG is supported
xyz isn't supported

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS