PHP 中的 imagecolorat() 函式


imagecolorat() 函式獲取畫素顏色的索引。

語法

imagecolorat( $img, $x, $y )

引數

  • img:用 imagecreatetruecolor() 函式建立一個影像。

  • x:點的 x 座標。

  • y:點的 y 座標。

返回值

imagecolorat() 函式返回顏色索引或在失敗時返回 FALSE。

示例

以下是一個示例

 即時演示

<?php
   $img = imagecreatefrompng("https://tutorialspoint.tw/images/tp-logo-diamond.png");
   $rgb = imagecolorat($img, 15, 25);
   $colors = imagecolorsforindex($img, $rgb);
   var_dump($colors);
?>

輸出

以下為輸出

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

更新日期:2019-12-31

279 次瀏覽

開啟您的職業生涯

透過完成課程獲取認證

開始學習
廣告
© . All rights reserved.