Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

ฟังก์ชัน imagecolorat() ใน PHP

คำอธิบาย

ฟังก์ชัน imagecolorat() ใช้ดัชนีสีของพิกเซลที่ตำแหน่งที่ระบุ

รูปแบบการใช้งาน (Syntax)

imagecolorat($img, $x, $y)

พารามิเตอร์

  • img: สร้างภาพด้วยฟังก์ชัน imagecreatetruecolor()

  • x: พิกัด x ของจุด

  • y: พิกัด y ของจุด

ค่าที่คืนกลับ

ฟังก์ชัน imagecolorat() คืนค่าดัชนีสีหรือ FALSE หากล้มเหลว

ตัวอย่าง

<?php
   $img = imagecreatefrompng("https://www.tutorialspoint.com/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)
}