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.



  • imagick::COLORSPACE_UNDEFINED (0)
  • imagick::COLORSPACE_RGB (1)
  • imagick::COLORSPACE_GRAY (2)
  • imagick::COLORSPACE_TRANSPARENT (3)
  • imagick::COLORSPACE_OHTA (4)
  • imagick::COLORSPACE_LAB (5)
  • imagick::COLORSPACE_XYZ (6)
  • imagick::COLORSPACE_YCBCR (7)
  • imagick::COLORSPACE_YCC (8)
  • imagick::COLORSPACE_YIQ (9)
  • imagick::COLORSPACE_YPBPR (10)
  • imagick::COLORSPACE_YUV (11)
  • imagick::COLORSPACE_CMYK (12)
  • imagick::COLORSPACE_SRGB (13)
  • imagick::COLORSPACE_HSB (14)
  • imagick::COLORSPACE_HSL (15)
  • imagick::COLORSPACE_HWB (16)
  • imagick::COLORSPACE_REC601LUMA (17)
  • imagick::COLORSPACE_REC709LUMA (19)
  • imagick::COLORSPACE_LOG (21)
  • imagick::COLORSPACE_CMY (22)

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
?>

chevron_right


Output:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
?>

chevron_right


Output:

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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.