PHP 中的 imagecolorset() 函数

programmingserver side programmingphp更新于 2025/7/6 5:52:17

imagecolorset() 函数设置指定调色板索引的颜色。使用此功能可在调色板图像中创建类似洪水填充的效果。

语法

imagecolorset ( img, index, red, green, blue, alpha )

参数

  • img:使用 imagecreatetruecolor() 函数创建的图像

  • index:调色板图像中的索引

  • red:红色成分的值

  • green:绿色成分的值

  • blue:蓝色成分的值

  • alpha:图像的透明度。

返回

imagecolorset() 函数不返回任何内容。

示例

以下是示例

<?php
   $img = imagecreate(550, 400);
   imagecolorallocate($img, 0, 0, 0);
   $bgcolor = imagecolorat($img, 70, 85);
   imagecolorset($img, $bgcolor, 30, 110, 150);
   header('Content-Type: image/png');
   imagepng($img);
   imagedestroy($img);
?>

输出

输出结果如下:


相关文章