GmagickPixel::setcolorvalue()函数是PHP中的内置函数,用于为给定的GmagickPixel颜色设置所提供颜色通道的标准化值。标准化值是介于0和1之间的浮点数。语法:
GmagickPixel GmagickPixel::setcolorvalue( int $color, float $value )
参数:该函数接受上述和以下描述的两个参数:
$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)
$value:它指定值。
返回值:成功时,此函数返回GmagickPixel对象。
异常:该函数在错误时抛出GmagickPixelException。
下面给出的程序说明了PHP中的GmagickPixel::setcolorvalue()函数:程序1:
的PHP
// Create a new gmagickPixel object
$imagickPixel = new GmagickPixel();
// Set the color value
$imagickPixel->setColorValue(gmagick::COLOR_RED, 0.8);
// Get the Color value with gmagick::COLOR_RED
$colorValue = $imagickPixel->getcolorvalue(gmagick::COLOR_RED);
echo $colorValue;
?>
输出:
0.8
使用的图片:
程序2:
的PHP
// Create a new gmagickPixel object
$imagickPixel = new GmagickPixel();
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
// Create a new GmagickPixel object
$gmagickPixel = new GmagickPixel();
// Set the color to red
$gmagickPixel->setcolor('red');
// Set the color value of red to 0.5 for light red
$gmagickPixel->setcolorvalue(gmagick::COLOR_RED, 0.5);
// Create a GmagickDraw object
$draw = new GmagickDraw();
// Set fill color using gmagickpixel
$draw->setfillcolor($gmagickPixel);
// Set the font size
$draw->setfontsize(40);
// Annotate a text
$draw->annotate(180, 180, 'GeeksforGeeks');
// Use of drawimage function
$gmagick->drawImage($draw);
// Display the output image
header("Content-Type:image/png");
echo $gmagick->getImageBlob();
?>
输出: