Open In App

PHP | Gmagick getimagetype() Function

The Gmagick::getimagetype() function is an inbuilt function in PHP which is used to get the image type.

Syntax:



int Gmagick::getimagetype( void )

Parameters: This function doesn’t accept any parameters.

Return Value: This function returns an integer value corresponding to one of the IMGTYPE constants.
All the IMGTYPE constants are listed below:



Exceptions: This function throws GmagickException on error.

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

Used Image:

Program 1:




<?php
  
// Create a new  Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
  
// Use getimagetype function
$res = $gmagick->getimagetype();
echo $res;
?>

Output:

6 // Which corresponds to gmagick::IMGTYPE_TRUECOLOR.

Program 2:




<?php
  
// Create a new  Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
  
// Set the Image Type 
$gmagick->setImageType(Gmagick::IMGTYPE_PALETTE); 
  
// Use getimagetype function
$res = $gmagick->getimagetype();
echo $res;
?>

Output:

4

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

Article Tags :