PHP | GmagickPixel getcolorvalue() Function

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

Syntax:

float GmagickPixel::getcolorvalue( int $color )

Parameters: This function accepts a single parameter $color which holds an integer value corresponding to one of the 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 the value of the color channel specified as a floating-point number between 0 and 1.

Exceptions: This function throws GmagickPixelException on error.



Below given programs illustrate the GmagickPixel::getcolorvalue() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

0.67843137254902

Used Image:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
  
// Get the image histogram 
$histogramElements = $gmagick->getimagehistogram(); 
     
// Get the 301th pixel 
$getPixel = $histogramElements[300]; 
    
// Get the Color value with gmagick::COLOR_GREEN 
$colorValue = $getPixel->getcolorvalue(gmagick::COLOR_GREEN); 
    
echo $colorValue
?> 

chevron_right


Output:

0.29803921568627

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




My Personal Notes arrow_drop_up

I love Open Source Culture have contributed to phpMyAdmin, LibreOffice, Ant-Design and Web is my passion

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.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.