Open In App

PHP | Gmagick getimagetype() Function

Last Updated : 21 Jan, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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:
  • gmagick::IMGTYPE_UNDEFINED (0)
  • gmagick::IMGTYPE_BILEVEL (1)
  • gmagick::IMGTYPE_GRAYSCALE (2)
  • gmagick::IMGTYPE_GRAYSCALEMATTE (3)
  • gmagick::IMGTYPE_PALETTE (4)
  • gmagick::IMGTYPE_PALETTEMATTE (5)
  • gmagick::IMGTYPE_TRUECOLOR (6)
  • gmagick::IMGTYPE_TRUECOLORMATTE (7)
  • gmagick::IMGTYPE_COLORSEPARATION (8)
  • gmagick::IMGTYPE_COLORSEPARATIONMATTE (9)
  • gmagick::IMGTYPE_OPTIMIZE (10)
Exceptions: This function throws GmagickException on error. Below given programs illustrate the Gmagick::getimagetype() function in PHP: Used Image: Program 1: php
<?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
<?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

Next Article

Similar Reads