imagecolorset
(PHP 4, PHP 5, PHP 7, PHP 8)
imagecolorset — 给指定调色板索引设定颜色
说明
function imagecolorset(
GdImage
int
int
int
int
int
): ?false
GdImage
$image,int
$color,int
$red,int
$green,int
$blue,int
$alpha = 0): ?false
本函数将调色板中指定的索引设定为指定的颜色。对于在调色板图像中创建类似区域填充(flood-fill)的效果很有用,免去了真的去填充的开销。
参数
image由图象创建函数(例如imagecreatetruecolor())返回的 GdImage 对象。
color
调色板中的索引值。
red
红色成分的值。
green
绿色成分的值。
blue
蓝色成分的值。
alpha
alpha 的值。
示例
示例 #1 imagecolorset() 示例
<?php
// 创建 300x100 图像
$im = imagecreate(300, 100);
// 设置背景为红色
imagecolorallocate($im, 255, 0, 0);
// 获取背景颜色索引
$bg = imagecolorat($im, 0, 0);
// 设置背景为蓝色
imagecolorset($im, $bg, 0, 0, 255);
// 输出图像到浏览器
header('Content-Type: image/png');
imagepng($im);
?>参见
- imagecolorat() - 取得某像素的颜色索引值
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
