PHP | Gmagick setimagecolorspace() Function

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('zambiatek.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('zambiatek.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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!




