Open In App

PHP | ImagickPixel getColorValueQuantum() function

Last Updated : 16 Jan, 2020
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report
The ImagickPixel::getColorValueQuantum() 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 lies in the quantum range where 65535 is maximum and 0 is lowest on contrary to getColorValue() function where 1 was highest and 0 was lowest. Syntax:
int ImagickPixel::getColorValueQuantum( 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 integer value containing the value of color. Exceptions: This function throws ImagickException on error. Below given programs illustrate the ImagickPixel::getColorValueQuantum() function in PHP: Program 1: php
<?php
// Create a new imagickPixel object
$imagickPixel = new ImagickPixel('#d4a62a');

// Get the Color value with imagick::COLOR_BLUE
$colorValue = $imagickPixel->getColorValueQuantum(imagick::COLOR_BLUE);
echo $colorValue;
?>
Output:
10794
Program 2: php
<?php
// Create a new imagick object
$imagick = new Imagick(
    'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
 
// Get the image histogram
$histogramElements = $imagick->getImageHistogram();
 
// Get the 501th pixel
$getPixel = $histogramElements[500];

// Get the Color value with imagick::COLOR_GREEN
$colorValue = $getPixel->getColorValueQuantum(imagick::COLOR_GREEN);

echo $colorValue;
?>
Output:
26214
Reference: https://www.php.net/manual/en/imagickpixel.getcolorvaluequantum.php

Similar Reads