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