GmagickPixel::getcolorvalue()函数是PHP中的内置函数,用于获取给定GmagickPixel颜色的所提供颜色通道的标准化值。归一化值是介于0和1之间的浮点数。
用法:
float GmagickPixel::getcolorvalue( int $color )
参数:该函数接受单个参数$color,该参数持有对应于COLOR常量之一的整数值。所有颜色常量的列表如下:
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)
返回值:此函数返回指定为0到1之间的浮点数的颜色通道的值。
异常:该函数在错误时抛出GmagickPixelException。
下面给出的程序说明了PHP中的GmagickPixel::getcolorvalue()函数:
程序1:
// 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;
?>
输出:
0.67843137254902
使用的图片:
程序2:
// 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;
?>
输出:
0.29803921568627