Imagecolorsforindex() PHP 函數

| | | | | | | | | | |
語法:
array imagecolorsforindex($image, $index)
參數:該函數採用上述兩個參數,如下所述:
  • $image:imagecreatetruecolor() 函數用於創建具有給定尺寸的圖像。該函數創建一個指定大小的空圖像。
  • $index:該參數用於指定顏色索引。
返回值:此函數返回一個關聯數組,其中包含指定索引處的紅色、綠色、藍色和 alpha 鍵值“Äã”。以下程序說明了 PHP 中的 imagecolorsforindex() 函數 : 程序 1:
//將圖片保存到變量中。$image = imagecreatefrompng ( ` https://media.engineerforengineer.org/w p-content / uploads/engineerforengineer-9.png ` );
//計算percular點的rgb像素值。$rgb = imagecolorat ( $image , 30, 25);
// 分配顏色名稱和值。 $colors = imagecolorsforindex ( $image , $rgb ); var_dump ( $colors ); ?>
輸出:< /b>
array (4) {["red"] = > int (34) ["green"] = > int (170) ["blue"] = > int (66) ["alpha"] = > int (0)}
程序2:
//將圖片保存到變量中。$image = imagecreatefrompng ( ` https://media.engineerforengineer.org/wp-content/uploads/col1.png ` );
// 索引值$index_x = 230; $index_y = 120;
// 計算percular點的rgb像素值。$rgba_color = imagecolorat ( $image , $index_x , $index_y );
// 分配顏色名稱和值。 $colors = imagecolorsforindex ( $image , $rgba_color ); var_dump ( $colors ); ?>
輸出:
array (4) {["red "] = > int (97) ["green"] = > int (57) ["blue"] = > int (104) ["alpha"] = > int (0)}
相關文章:
  • PHP | Imagecolorclosestalpha() 函數
  • PHP | imagecolorat() 函數
鏈接: http://php.net/manual/en/function.imagecolorsforindex.php