PHP 中的 imagecolorsforindex() 函数


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

语法

imagecolorsforindex ( img, index )

参数

  • img:利用 imagecreatetruecolor() 创建一个图像

  • 索引:设置颜色索引。

返回

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

示例

提供以下示例

 实时演示

<?php
   $img = imagecreatefrompng('https://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) }

最后更新时间:2019-12-31

67 次浏览

启动您的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.