Wednesday, July 3, 2024
HomeLanguagesPhpPHP | 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!

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments