Friday, June 12, 2026
HomeLanguagesPHP | Gmagick getimagetype() Function

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:

  • 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
  
// Create a new  Gmagick object
$gmagick = new Gmagick('neveropen.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('neveropen.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

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!
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS