Thursday, October 9, 2025
HomeLanguagesPHP | ImagickPixel getColorValue() function

PHP | ImagickPixel getColorValue() function

The ImagickPixel::getColorValue() function is an inbuilt function in PHP which is used to get the normalized value of the provided color channel for a given ImagickPixel’s color. The normalized value is a floating-point number between 0 and 1.

Syntax:

float ImagickPixel::getColorValue( int $color )

Parameters:This function accepts a single parameter $color which holds one of COLOR constants.

List of all COLOR constants are given below:

  • imagick::COLOR_BLACK (11)
  • imagick::COLOR_BLUE (12)
  • imagick::COLOR_CYAN (13)
  • imagick::COLOR_GREEN (14)
  • imagick::COLOR_RED (15)
  • imagick::COLOR_YELLOW (16)
  • imagick::COLOR_MAGENTA (17)
  • imagick::COLOR_OPACITY (18)
  • imagick::COLOR_ALPHA (19)
  • imagick::COLOR_FUZZ (20)

Return Value: This function returns an float value containing the normalized value of the color value.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the ImagickPixel::getColorValue() function in PHP:
Program 1:




<?php
// Create a new imagickPixel object
$imagickPixel = new ImagickPixel('#ad4c45');
  
// Get the Color value with imagick::COLOR_RED
$colorValue = $imagickPixel->getColorValue(imagick::COLOR_RED);
echo $colorValue;
?>


Output:

0.67843137254902

Program 2:




<?php
// Create a new imagick object
$imagick = new Imagick(
   
// Get the image histogram
$histogramElements = $imagick->getImageHistogram();
   
// Get the 301th pixel
$getPixel = $histogramElements[300];
  
// Get the Color value with imagick::COLOR_GREEN
$colorValue = $getPixel->getColorValue(imagick::COLOR_GREEN);
  
echo $colorValue;
?>


Output:

0.29803921568627

Reference: https://www.php.net/manual/en/imagickpixel.getcolorvalue.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
RELATED ARTICLES

Most Popular

Dominic
32346 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11877 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11940 POSTS0 COMMENTS
Shaida Kate Naidoo
6835 POSTS0 COMMENTS
Ted Musemwa
7095 POSTS0 COMMENTS
Thapelo Manthata
6789 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS