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('zambiatek.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('zambiatek.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, zambiatek 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!




