php value用法,PHP GmagickPixel setcolorvalue()用法及代码示例

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

使用的图片:

228c98d6ff62e907625fff7fe242f4b7.png

程序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();

?>

输出:

6949286fc9eaf44da902658d6c10c521.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值