PHP | Gmagick setimagetype() Function
Last Updated :
23 Jan, 2020
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
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$gmagick ->setimagetype(1);
header( "Content-Type: image/png" );
echo $gmagick ;
?>
|
Output:
Program 2:
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$gmagick ->setimagetype(3);
header( "Content-Type: image/png" );
echo $gmagick ;
?>
|
Output:
Program 3:
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$draw = new GmagickDraw();
$draw ->setFillColor( 'white' );
$draw ->rectangle(0, 0, 800, 400);
$draw ->setFillColor( 'red' );
$draw ->setfontsize(50);
$draw ->annotate(30, 100, 'GeeksforGeeks' );
$gmagick ->drawImage( $draw );
$gmagick ->setimagetype(2);
header( "Content-Type: image/png" );
echo $gmagick ;
?>
|
Output:
Reference: https://www.php.net/manual/en/gmagick.setimagetype.php
Share your thoughts in the comments
Please Login to comment...