Open In App

PHP | Imagick setColorspace() Function

The Imagick::setColorspace() function is an inbuilt function in PHP which is used to set the global colorspace value of an image.

Syntax:



bool Imagick::setColorspace( 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 given programs illustrate the Imagick::setColorspace() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Set the colorspace
$imagick->setColorspace(imagick::COLORSPACE_RGB);
  
// Get the colorspace
$colorSpace = $imagick->getColorSpace();
  
// Display the colorspace
echo $colorSpace;
?>

Output:

1

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Set the colorspace
$imagick->setColorspace(imagick::COLORSPACE_YIQ);
  
// Get the colorspace
$colorSpace = $imagick->getColorSpace();
  
// Display the colorspace
echo $colorSpace;
?>

Output:

9

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


Article Tags :