Open In App

PHP | Imagick setImageColorspace() Function

The Imagick::setImageColorspace() function is an inbuilt function in PHP which is used to set the image colorspace.

Syntax:



bool Imagick::setImageColorspace( int $colorspace )

Parameters: This function accepts a single parameter $colorspace which holds an integer value corresponding to one of COLORSPACE constants.

Return Value: This function returns TRUE on success.



Exceptions: This function throws ImagickException on error.

Below programs illustrate the Imagick::setImageColorspace() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
   
// Set the image colorspace
$imagick->setImageColorspace(imagick::COLORSPACE_RGB);
  
// 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 colorspace
$imagick->setImageColorspace(imagick::COLORSPACE_OHTA);
  
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

Output:

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


Article Tags :