Skip to content
Related Articles

Related Articles

PHP | Gmagick setimagecolorspace() Function

Improve Article
Save Article
  • Last Updated : 17 Jan, 2020
Improve Article
Save Article

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

Syntax:

Gmagick Gmagick::setimagecolorspace( int $colorspace )

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

COLORSPACE constants:

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

Return Value: This function returns TRUE on success.

Exceptions: This function throws GmagickException on error.

Image used: To capture the canvas area.

Below given programs illustrate the Gmagick::setimagecolorspace() function in PHP:

Program 1: Making image Gray.




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
  
// Set the image colorspace to Gmagick::COLORSPACE_GRAY
$gmagick->setimagecolorspace(Gmagick::COLORSPACE_GRAY);
  
// Display the image
header("Content-Type: image/png");
echo $gmagick;
?>


Output:

Program 2: SRGB Colorspace.




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
  
// Set the image colorspace to Gmagick::COLORSPACE_SRGB
$gmagick->setimagecolorspace(Gmagick::COLORSPACE_SRGB);
  
// Display the image
header("Content-Type: image/png");
echo $gmagick;
?>


Output:

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


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!