Open In App

PHP | Imagick setImageType() Function

The Imagick::setImageType() function is an inbuilt function in PHP which is used to set the image type.
Syntax: 
 

bool Imagick::setImageType( int $image_type )

Parameters: This function accepts a single parameter $image_type which contains an integer value corresponding to one of IMGTYPE constants. We can also pass the constant directly like setImageType(imagick::IMGTYPE_GRAYSCALE);.
All the IMGTYPE constants are listed below: 
 



Return Value: This function returns TRUE on success.
Below programs illustrate the Imagick::setImageType() function in PHP:
Program 1: 
 




<?php
 
// Create a new imagick object
$imagick = new Imagick(
 
// Set the Image Type to imagick::IMGTYPE_GRAYSCALEMATTE
$imagick->setImageType(3);
 
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

Output: 
 



Program 2: 
 




<?php
 
// Create a new imagick object
$imagick = new Imagick(
 
// Set the Image Type to imagick::IMGTYPE_BILEVEL
$imagick->setImageType(1);
 
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

Output: 
 

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


Article Tags :