PHP | Gmagick queryformats() Function
Last Updated :
14 Jan, 2020
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
$gmagick = new Gmagick();
$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
$gmagick = new Gmagick();
$formats = $gmagick ->queryformats( '*' );
checkFormat( 'JPEG' , $formats );
checkFormat( 'xyz' , $formats );
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...