这个 imagecolorsforindex() 函数是PHP中的一个内置函数,用于获取给定索引处的颜色。此函数返回一个数组,其中包含指定颜色值的红色、绿色、蓝色和alpha键值。 语法:
null
array imagecolorsforindex ( $image, $index )
参数: 该函数接受两个参数,如下所述:
- $image: 函数用于创建给定大小的图像。此函数用于创建给定大小的空白图像。
- $index: 此参数用于指定颜色索引。
返回值: 此函数返回一个关联数组,其中包含给定索引处的红色、绿色、蓝色和alpha键值。 下面的程序说明了 imagecolorsforindex() PHP中的函数: 项目1:
php
<?php // store the image in variable. $image = imagecreatefrompng( // Calculate rgb pixel value at particular point. $rgb = imagecolorat( $image , 30, 25); // Assign color name and its value. $colors = imagecolorsforindex( $image , $rgb ); var_dump( $colors ); ?> |
输出:
array(4) { ["red"]=> int(34) ["green"]=> int(170) ["blue"]=> int(66) ["alpha"]=> int(0) }
项目2:
php
<?php // store the image in variable. $image = imagecreatefrompng( // index value $index_x = 230; $index_y = 120; // Calculate rgb pixel value at particular point. $rgba_color = imagecolorat( $image , $index_x , $index_y ); // Assign color name and its value. $colors = imagecolorsforindex( $image , $rgba_color ); var_dump( $colors ); ?> |
输出:
array(4) { ["red"]=> int(97) ["green"]=> int(57) ["blue"]=> int(104) ["alpha"]=> int(0) }
相关文章:
参考: http://php.net/manual/en/function.imagecolorsforindex.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END