PHP 中的 imagecolorsforindex() 函数

phpserver side programmingprogramming更新于 2025/7/6 6:07:17

imagecolorsforindex() 函数获取索引的颜色。

语法

imagecolorsforindex ( img, index )

参数

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

  • Index:设置颜色索引。

返回

imagecolorsforindex() 函数返回一个关联数组,其中包含红色、绿色、蓝色和 alpha 键,这些键包含指定颜色索引的相应值。

示例

以下是示例

<?php
   $img = imagecreatefrompng('http://www.tutorialspoint.com/images/tp-logo-diamond.png');
   $x = 25;
   $y = 45;
   $rgb = imagecolorat($img, 25, 45);
   $colors = imagecolorsforindex($img, $rgb);
   var_dump($colors);
?>

输出

输出结果如下:

array(4) { ["red"]=> int(255) ["green"]=> int(255) ["blue"]=> int(255) ["alpha"]=> int(127) }

相关文章