The Gmagick::setimagetype() function is an inbuilt function in PHP which is used to set the image type.
Syntax:
Gmagick Gmagick::setimagetype( int $imgType )
Parameters: This function accepts a single parameter $imgType which holds 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)
Return Value: This function returns Gmagick object on success.
Exceptions: This function throws GmagickException on error.
Below given programs illustrate the Gmagick::setimagetype() function in PHP:
Used Image:
Program 1:
<?php   // Create a new Gmagick object $gmagick = new Gmagick('neveropen.png');   // Set the image type $gmagick->setimagetype(1);   // Display the image header("Content-Type: image/png"); echo $gmagick; ?> |
Output:
Program 2:
<?php   // Create a new Gmagick object $gmagick = new Gmagick('neveropen.png');   // Set the image type $gmagick->setimagetype(3);   // Display the image header("Content-Type: image/png"); echo $gmagick; ?> |
Output:
Program 3:
<?php   // Create a new Gmagick object $gmagick = new Gmagick('neveropen.png');    // Create a GmagickDraw object $draw = new GmagickDraw();    // Set the color $draw->setFillColor('white');    // Function to draw rectangle $draw->rectangle(0, 0, 800, 400);    // Set the fill color $draw->setFillColor('red');    // Set the font size $draw->setfontsize(50);    // Annotate a text $draw->annotate(30, 100, 'neveropen');    // Use of drawimage function $gmagick->drawImage($draw);   // Set the image type $gmagick->setimagetype(2);   // Display the image header("Content-Type: image/png"); echo $gmagick; ?> |
Output:
Reference: https://www.php.net/manual/en/gmagick.setimagetype.php

