Tuesday, June 16, 2026
HomeLanguagesPHP | Imagick getImageType() Function

PHP | Imagick getImageType() Function

The Imagick::getImageType() function is an inbuilt function in PHP which is used to get the potential image type.

Syntax:

int Imagick::getImageType( void )

Parameters: This function doesn’t accepts any parameter.

Return Value: This function returns an integer value corresponding to one of IMGTYPE constants.

All the IMGTYPE constants are listed below:

  • imagick::IMGTYPE_UNDEFINED (0)
  • imagick::IMGTYPE_BILEVEL (1)
  • imagick::IMGTYPE_GRAYSCALE (2)
  • imagick::IMGTYPE_GRAYSCALEMATTE (3)
  • imagick::IMGTYPE_PALETTE (4)
  • imagick::IMGTYPE_PALETTEMATTE (5)
  • imagick::IMGTYPE_TRUECOLOR (6)
  • imagick::IMGTYPE_TRUECOLORMATTE (7)
  • imagick::IMGTYPE_COLORSEPARATION (8)
  • imagick::IMGTYPE_COLORSEPARATIONMATTE (9)
  • imagick::IMGTYPE_OPTIMIZE (10)

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the Imagick::getImageType() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Get the Image Type
$type = $imagick->getImageType();
echo $type;
?>


Output:

 7 // Which corresponds to imagick::IMGTYPE_TRUECOLORMATTE.

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Set the Image Type
$imagick->setImageType(3);
  
// Get the Image Type
$type = $imagick->getImageType();
echo $type;
?>


Output:

 3 // Which corresponds to imagick::IMGTYPE_GRAYSCALEMATTE.

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

RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12014 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